|
|
|
@ -4,7 +4,6 @@ import cn.estsh.i3plus.core.api.iservice.busi.ISysConfigService;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
|
|
|
|
|
import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.MailConfig;
|
|
|
|
|
import cn.estsh.i3plus.pojo.platform.bean.SysConfig;
|
|
|
|
|
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
|
|
|
|
@ -38,8 +37,8 @@ public class MailUtil {
|
|
|
|
|
public static final Logger LOGGER = LoggerFactory.getLogger(MailUtil.class);
|
|
|
|
|
|
|
|
|
|
// 收件人
|
|
|
|
|
private Address[] to = null;
|
|
|
|
|
private Address[] cc = null;
|
|
|
|
|
private Address[] to = new Address[]{};
|
|
|
|
|
private Address[] cc = new Address[]{};
|
|
|
|
|
private int mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
|
|
|
|
|
private String from = "";
|
|
|
|
|
private String nick = "";
|
|
|
|
@ -58,6 +57,7 @@ public class MailUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化服务器邮箱参数
|
|
|
|
|
*
|
|
|
|
|
* @return 初始化
|
|
|
|
|
*/
|
|
|
|
|
public MailUtil init() {
|
|
|
|
@ -77,7 +77,7 @@ public class MailUtil {
|
|
|
|
|
this.mailSwitch = CommonEnumUtil.TRUE_OR_FALSE.FALSE.getValue();
|
|
|
|
|
}
|
|
|
|
|
return this;
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("邮箱配置初始化失败!", e.getMessage());
|
|
|
|
|
return new MailUtil();
|
|
|
|
|
}
|
|
|
|
@ -86,6 +86,7 @@ public class MailUtil {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 初始化服务器邮箱参数
|
|
|
|
|
*
|
|
|
|
|
* @param mailConfig 邮箱配置信息
|
|
|
|
|
* @return 初始化
|
|
|
|
|
*/
|
|
|
|
@ -101,7 +102,7 @@ public class MailUtil {
|
|
|
|
|
this.isAuthenticationSMTP = true;
|
|
|
|
|
|
|
|
|
|
return this;
|
|
|
|
|
} catch (Exception e){
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
LOGGER.error("邮箱配置初始化失败!", e.getMessage());
|
|
|
|
|
return new MailUtil();
|
|
|
|
|
}
|
|
|
|
@ -184,13 +185,18 @@ public class MailUtil {
|
|
|
|
|
this.contentType = contentType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取邮箱地址
|
|
|
|
|
* @param add 邮箱地址字符串
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
private Address[] getAddress(String[] add) {
|
|
|
|
|
Address[] a = new Address[add.length];
|
|
|
|
|
for (int i = 0; i < add.length; i++) {
|
|
|
|
|
try {
|
|
|
|
|
a[i] = new InternetAddress(add[i]);
|
|
|
|
|
} catch (AddressException ex) {
|
|
|
|
|
LOGGER.error("邮箱地址错误!",ex.getMessage());
|
|
|
|
|
LOGGER.error("【" + add[i] + "】邮箱地址错误!", ex.getMessage());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return a;
|
|
|
|
@ -200,9 +206,9 @@ public class MailUtil {
|
|
|
|
|
* 发送邮件
|
|
|
|
|
*/
|
|
|
|
|
public void send() {
|
|
|
|
|
try{
|
|
|
|
|
try {
|
|
|
|
|
// 是否开启邮箱配置
|
|
|
|
|
if(this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()){
|
|
|
|
|
if (this.mailSwitch != CommonEnumUtil.TRUE_OR_FALSE.TRUE.getValue()) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Properties server = new Properties();
|
|
|
|
@ -250,7 +256,7 @@ public class MailUtil {
|
|
|
|
|
}
|
|
|
|
|
LOGGER.info("邮件发送成功");
|
|
|
|
|
|
|
|
|
|
} catch (SMTPAddressFailedException e){
|
|
|
|
|
} catch (SMTPAddressFailedException e) {
|
|
|
|
|
LOGGER.error(e.getClass() + "\t" + e.getMessage());
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
@ -258,7 +264,7 @@ public class MailUtil {
|
|
|
|
|
.setErrorDetail(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getDescription())
|
|
|
|
|
.setErrorSolution("请重新设置收件人")
|
|
|
|
|
.build();
|
|
|
|
|
} catch (AuthenticationFailedException e){
|
|
|
|
|
} catch (AuthenticationFailedException e) {
|
|
|
|
|
LOGGER.error(e.getClass() + "\t" + e.getMessage());
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
@ -266,7 +272,7 @@ public class MailUtil {
|
|
|
|
|
.setErrorDetail(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getDescription())
|
|
|
|
|
.setErrorSolution("请重新设置账号或密码")
|
|
|
|
|
.build();
|
|
|
|
|
} catch (MessagingException e){
|
|
|
|
|
} catch (MessagingException e) {
|
|
|
|
|
LOGGER.error(e.getClass() + "\t" + e.getMessage());
|
|
|
|
|
throw ImppExceptionBuilder.newInstance()
|
|
|
|
|
.setSystemID(CommonEnumUtil.SOFT_TYPE.CORE.getCode())
|
|
|
|
|