|
@ -14,6 +14,7 @@ import com.yihu.jw.restmodel.base.saas.SaasTypeDictVO;
|
|
|
import com.yihu.jw.restmodel.base.saas.SaasVO;
|
|
|
import com.yihu.jw.restmodel.web.Envelop;
|
|
|
import com.yihu.jw.restmodel.web.ListEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.ObjEnvelop;
|
|
|
import com.yihu.jw.restmodel.web.endpoint.EnvelopRestEndpoint;
|
|
|
import com.yihu.jw.rm.base.BaseRequestMapping;
|
|
|
import io.swagger.annotations.Api;
|
|
@ -27,7 +28,15 @@ import org.springframework.mail.SimpleMailMessage;
|
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
import javax.mail.*;
|
|
|
import javax.mail.internet.InternetAddress;
|
|
|
import javax.mail.internet.MimeBodyPart;
|
|
|
import javax.mail.internet.MimeMessage;
|
|
|
import javax.mail.internet.MimeMultipart;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.util.Calendar;
|
|
|
import java.util.List;
|
|
|
import java.util.Properties;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
/**
|
|
@ -154,7 +163,15 @@ public class RegisterEndpoint extends EnvelopRestEndpoint {
|
|
|
//建立邮件消息
|
|
|
SimpleMailMessage mainMessage = new SimpleMailMessage();
|
|
|
//发送者
|
|
|
// String nick="";
|
|
|
// try{
|
|
|
// nick=javax.mail.internet.MimeUtility.encodeText("厦门i健康");
|
|
|
// }catch(UnsupportedEncodingException e){
|
|
|
// e.printStackTrace();
|
|
|
// }
|
|
|
// mainMessage.setFrom(new InternetAddress(nick+" <"+"763558454@qq.com"+">"));
|
|
|
mainMessage.setFrom(username);
|
|
|
// mainMessage.setFrom(nick+"<"+username+">");
|
|
|
//接收者
|
|
|
mainMessage.setTo(email);
|
|
|
//发送的标题
|
|
@ -176,11 +193,90 @@ public class RegisterEndpoint extends EnvelopRestEndpoint {
|
|
|
.append(emailTemplateConfigDO.getKeyword5()).append(emailTemplateConfigDO.getUrl())
|
|
|
.append("\n").append("\n").append(emailTemplateConfigDO.getRemark());
|
|
|
}
|
|
|
mainMessage.setSubject("租户注册-验证码");
|
|
|
mainMessage.setSubject("健康之路城市i健康");
|
|
|
|
|
|
mainMessage.setText(content.toString());
|
|
|
jms.send(mainMessage);
|
|
|
redisTemplate.opsForValue().set(redisPrefix + email, captcha, 10, TimeUnit.MINUTES);
|
|
|
return success("发送成功");
|
|
|
}
|
|
|
|
|
|
@PostMapping(value = "/testSendEmailMethod")
|
|
|
@ApiOperation(value = "测试邮件发送")
|
|
|
public Envelop testSendEmailMethod(@ApiParam(name = "email", value = "邮箱地址", required = true)
|
|
|
@RequestParam String email) throws Exception {
|
|
|
|
|
|
if(!ValidateUtil.isValidEmail(email)){
|
|
|
return failed(errorCodeUtil.getErrorMsg(BaseErrorCode.Saas.EMAIL_IS_NOT_FORMAT), Envelop.class);
|
|
|
}
|
|
|
// 1.创建一个程序与邮件服务器会话对象 Session
|
|
|
Properties props = new Properties();
|
|
|
props.setProperty("mail.transport.protocol", "SMTP");// 连接协议
|
|
|
props.setProperty("mail.smtp.host", "smtp.163.com");// 连接协议
|
|
|
props.setProperty("mail.smtp.port", "25");// 连接协议
|
|
|
// 指定验证为true
|
|
|
props.setProperty("mail.smtp.auth", "true");
|
|
|
props.setProperty("mail.smtp.timeout","1000");
|
|
|
// 验证账号及密码,密码需要是第三方授权码
|
|
|
Authenticator auth = new Authenticator() {
|
|
|
public PasswordAuthentication getPasswordAuthentication(){
|
|
|
return new PasswordAuthentication(username, "xmijk181016jkzl");
|
|
|
}
|
|
|
};
|
|
|
Session session = Session.getInstance(props, auth);
|
|
|
|
|
|
// 2.创建一个Message,它相当于是邮件内容
|
|
|
MimeMessage message = new MimeMessage(session);
|
|
|
try {
|
|
|
//防止成为垃圾邮件,披上outlook的马甲
|
|
|
// message.addHeader("X-Mailer","Microsoft Outlook Express 6.00.2900.2869");
|
|
|
message.addHeader("X-Priority", "3");
|
|
|
|
|
|
message.addHeader("X-MSMail-Priority", "Normal");
|
|
|
|
|
|
message.addHeader("X-Mailer", "Microsoft Outlook Express 6.00.2900.2869"); //本文以outlook名义发送邮件,不会被当作垃圾邮件
|
|
|
|
|
|
message.addHeader("X-MimeOLE", "Produced By Microsoft MimeOLE V6.00.2900.2869");
|
|
|
|
|
|
message.addHeader("ReturnReceipt", "1");
|
|
|
|
|
|
// 设置发送者
|
|
|
message.setFrom(new InternetAddress(username));
|
|
|
// 设置发送方式与接收者
|
|
|
message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress(email));
|
|
|
// 设置主题
|
|
|
message.setSubject("健康之路城市i健康");
|
|
|
// mainMessage.setSubject("租户注册-验证码");
|
|
|
|
|
|
//创建消息主体
|
|
|
MimeBodyPart messageBodyPart = new MimeBodyPart();
|
|
|
//发送的内容
|
|
|
String captcha = String.valueOf(Math.random()).substring(2, 8);
|
|
|
StringBuilder content = new StringBuilder("您好!\n感谢您注册健康之路城市i健康。\n");
|
|
|
content.append("您的验证码是:").append(captcha);
|
|
|
content.append("。 (验证码10分钟内有效)");
|
|
|
|
|
|
|
|
|
messageBodyPart.setText(content.toString());
|
|
|
|
|
|
// 创建多重消息
|
|
|
Multipart multipart=new MimeMultipart();
|
|
|
|
|
|
multipart.addBodyPart(messageBodyPart);
|
|
|
|
|
|
// 设置邮件消息发送的时间
|
|
|
message.setSentDate(Calendar.getInstance().getTime());
|
|
|
// 设置内容
|
|
|
message.setContent(multipart, "text/html;charset=utf-8");
|
|
|
|
|
|
// 3.创建 Transport用于将邮件发送
|
|
|
Transport.send(message);
|
|
|
}catch (Exception e){
|
|
|
e.printStackTrace();
|
|
|
return failed(e.getMessage(),ObjEnvelop.class);
|
|
|
}
|
|
|
|
|
|
return success("success",true);
|
|
|
|
|
|
}
|
|
|
}
|