Merge remote-tracking branch 'origin/dev' into test

yun-zuoyi
汪云昊 5 years ago
commit 696c21097c

@ -15,6 +15,7 @@ import cn.estsh.i3plus.pojo.base.bean.BaseThreadLocal;
import cn.estsh.i3plus.pojo.base.bean.ListPager; import cn.estsh.i3plus.pojo.base.bean.ListPager;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil;
import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.ResourceEnumUtil;
import cn.estsh.i3plus.pojo.model.common.CloudPagerModel;
import cn.estsh.i3plus.pojo.model.license.ImppLicense; import cn.estsh.i3plus.pojo.model.license.ImppLicense;
import cn.estsh.i3plus.pojo.model.platform.UserDetailModel; import cn.estsh.i3plus.pojo.model.platform.UserDetailModel;
import cn.estsh.i3plus.pojo.model.platform.UserDetailPagerModel; import cn.estsh.i3plus.pojo.model.platform.UserDetailPagerModel;
@ -243,6 +244,9 @@ public class WhiteController extends CoreBaseController {
log.setLogLoginStatus(userLoginStatus); log.setLogLoginStatus(userLoginStatus);
log.setLogLoginBrowser(ServletRequestTool.getRequestBrowser(request)); log.setLogLoginBrowser(ServletRequestTool.getRequestBrowser(request));
log.setLogLoginHost(IpAddr); log.setLogLoginHost(IpAddr);
if (StringUtils.isBlank(log.getLogLoginHost()) || "null".equals(log.getLogLoginHost())) {
log.setLogLoginHost(ServletRequestTool.getRequestHost(request));
}
log.setLogLoginPlatform(CommonEnumUtil.LOG_LOGIN_PLATFORM.descOf(ServletRequestTool.getRequestOs(request))); log.setLogLoginPlatform(CommonEnumUtil.LOG_LOGIN_PLATFORM.descOf(ServletRequestTool.getRequestOs(request)));
log.setLogLoginDateTime(TimeTool.getNowTime(true)); log.setLogLoginDateTime(TimeTool.getNowTime(true));
@ -280,6 +284,23 @@ public class WhiteController extends CoreBaseController {
} }
} }
@PostMapping(value = "/sys-locale-resource/query")
@ApiOperation(value = "按条件查询资源")
public ResultBean findSysLocaleResource(@RequestBody CloudPagerModel<SysLocaleResource> pagerModel){
try {
ListPager<SysLocaleResource> resourceList = sysLocaleResourceService.querySysLocaleResourceByPager(
pagerModel.getObj(), pagerModel.getPager()
);
return ResultBean.success("操作成功")
.setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode())
.setListPager(resourceList);
}catch(ImppBusiException busExcep){
return ResultBean.fail(busExcep);
}catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
}
}
@PostMapping(value = "/find-resource") @PostMapping(value = "/find-resource")
@ApiOperation(value = "按条件查询资源") @ApiOperation(value = "按条件查询资源")
public ResultBean<SysLocaleResource> findSysLocaleResource(@RequestBody SysLocaleResource resource){ public ResultBean<SysLocaleResource> findSysLocaleResource(@RequestBody SysLocaleResource resource){

@ -57,8 +57,8 @@ public class SysLogUserLoginController extends CoreBaseController {
try { try {
ListPager logUserLoginListPager = sysLogUserLoginService.querySysLogUserLoginByPager(sysLogUserLogin, pager); ListPager logUserLoginListPager = sysLogUserLoginService.querySysLogUserLoginByPager(sysLogUserLogin, pager);
return ResultBean.success("查询成功").setListPager(logUserLoginListPager).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()); return ResultBean.success("查询成功").setListPager(logUserLoginListPager).setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
}catch(ImppBusiException busExcep){ }catch(ImppBusiException e){
return ResultBean.fail(busExcep); return ResultBean.fail(e);
}catch(Exception e){ }catch(Exception e){
return ImppExceptionBuilder.newInstance().buildExceptionResult(e); return ImppExceptionBuilder.newInstance().buildExceptionResult(e);
} }
@ -75,14 +75,14 @@ public class SysLogUserLoginController extends CoreBaseController {
String fileName = "log-user-login-" + System.currentTimeMillis() + ".xls"; String fileName = "log-user-login-" + System.currentTimeMillis() + ".xls";
file = new File(fileName); file = new File(fileName);
file.createNewFile(); file.createNewFile();
File excle = excelTool.exportData(file, list, SysLogUserLogin.class, (LinkedHashMap<String, String>) ExcelTool.getColName(SysLogUserLogin.class)); File excel = excelTool.exportData(file, list, SysLogUserLogin.class, (LinkedHashMap<String, String>) ExcelTool.getColName(SysLogUserLogin.class));
response.setContentType("application/force-download"); // 设置强制下载不打开 response.setContentType("application/force-download"); // 设置强制下载不打开
response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); // 设置文件名 response.addHeader("Content-Disposition", "attachment;fileName=" + fileName); // 设置文件名
response.addHeader("Content-type", FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(fileName,true))); response.addHeader("Content-type", FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(fileName,true)));
// 设置文件名 // 设置文件名
try (BufferedInputStream bis = new BufferedInputStream(new DataInputStream(new FileInputStream(excle)))) { try (BufferedInputStream bis = new BufferedInputStream(new DataInputStream(new FileInputStream(excel)))) {
OutputStream os = response.getOutputStream(); OutputStream os = response.getOutputStream();
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int i = bis.read(buffer); int i = bis.read(buffer);

@ -40,6 +40,8 @@ import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static cn.estsh.i3plus.platform.common.util.CommonConstWords.REDIS_PREFIX_LOCK_GET_ORDER_NO;
/** /**
* @Description : * @Description :
* @Reference : * @Reference :
@ -152,8 +154,14 @@ public class SysOrderNoRuleController extends CoreBaseController {
public ResultBean deleteSysOrderNoRuleById(@PathVariable("id") String idStr) { public ResultBean deleteSysOrderNoRuleById(@PathVariable("id") String idStr) {
try { try {
ValidatorBean.checkNotNull(idStr, "id不能为空"); ValidatorBean.checkNotNull(idStr, "id不能为空");
SysOrderNoRule sysOrderNoRule = sysOrderNoRuleService.getSysOrderNoRuleById(Long.parseLong(idStr));
ValidatorBean.checkNotNull(sysOrderNoRule,"单号规则不存在");
// 清理缓存
redisRes.deleteKey(REDIS_PREFIX_LOCK_GET_ORDER_NO + ":" + sysOrderNoRule.getOrderNoRuleCode());
sysOrderNoRuleService.deleteSysOrderNoRuleById(Long.parseLong(idStr)); // 删除
sysOrderNoRuleService.deleteSysOrderNoRuleById(sysOrderNoRule.getId());
return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode()); return ResultBean.success("操作成功").setCode(ResourceEnumUtil.MESSAGE.SUCCESS.getCode());
} catch (ImppBusiException busExcep) { } catch (ImppBusiException busExcep) {
return ResultBean.fail(busExcep); return ResultBean.fail(busExcep);

@ -1,5 +1,7 @@
package cn.estsh.i3plus.core.apiservice.mq; package cn.estsh.i3plus.core.apiservice.mq;
import cn.estsh.i3plus.core.api.iservice.busi.ISysFileAttachService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysFileService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysMessageService; import cn.estsh.i3plus.core.api.iservice.busi.ISysMessageService;
import cn.estsh.i3plus.core.api.iservice.busi.ISysUserService; import cn.estsh.i3plus.core.api.iservice.busi.ISysUserService;
import cn.estsh.i3plus.core.apiservice.util.MailUtil; import cn.estsh.i3plus.core.apiservice.util.MailUtil;
@ -8,12 +10,12 @@ import cn.estsh.i3plus.platform.common.tool.JsonUtilTool;
import cn.estsh.i3plus.platform.common.tool.TimeTool; import cn.estsh.i3plus.platform.common.tool.TimeTool;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords; import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil; import cn.estsh.i3plus.pojo.base.enumutil.ImppEnumUtil;
import cn.estsh.i3plus.pojo.platform.bean.SysMessage; import cn.estsh.i3plus.pojo.platform.bean.*;
import cn.estsh.i3plus.pojo.platform.bean.SysRefUserMessage; import cn.estsh.impp.framework.boot.fileservice.ImppFileService;
import cn.estsh.i3plus.pojo.platform.bean.SysUser;
import cn.estsh.impp.framework.boot.util.RedisCacheTool; import cn.estsh.impp.framework.boot.util.RedisCacheTool;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.rabbitmq.client.Channel; import com.rabbitmq.client.Channel;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.exception.ExceptionUtils; import org.apache.commons.lang3.exception.ExceptionUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -25,6 +27,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
/** /**
* @Description : * @Description :
@ -40,11 +43,22 @@ public class MessageMailQueueReceiver {
@Autowired @Autowired
private ISysMessageService sysMessageService; private ISysMessageService sysMessageService;
@Autowired @Autowired
private ISysUserService sysUserService; private ISysUserService sysUserService;
@Autowired @Autowired
private MailUtil mailUtil; private MailUtil mailUtil;
@Autowired
private ISysFileAttachService sysFileAttachService;
@Autowired
private ISysFileService sysFileService;
@Autowired
private ImppFileService fileService;
/** /**
* *
* *
@ -55,7 +69,7 @@ public class MessageMailQueueReceiver {
@RabbitListener(queues = PlatformConstWords.QUEUE_IMPP_MESSAGE_MAIL) @RabbitListener(queues = PlatformConstWords.QUEUE_IMPP_MESSAGE_MAIL)
public void processImppMail(String data, Channel channel, Message message) { public void processImppMail(String data, Channel channel, Message message) {
SysMessage msg = JsonUtilTool.decode(data, SysMessage.class); SysMessage msg = JsonUtilTool.decode(data, SysMessage.class);
Long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
try { try {
LOGGER.debug("【MQ-QUEUE_IMPP_MESSAGE_MAIL】数据接收成功{}", msg); LOGGER.debug("【MQ-QUEUE_IMPP_MESSAGE_MAIL】数据接收成功{}", msg);
if (msg.getMessageSendTime() == null) { if (msg.getMessageSendTime() == null) {
@ -70,24 +84,42 @@ public class MessageMailQueueReceiver {
// 默认发送成功 // 默认发送成功
msg.setSendStatus(ImppEnumUtil.MESSAGE_SEND_STATUS.SEND_SUCCESS.getValue()); msg.setSendStatus(ImppEnumUtil.MESSAGE_SEND_STATUS.SEND_SUCCESS.getValue());
// 设置邮件主题内容及收件人 // 初始化邮箱工具信息
mailUtil.init(); mailUtil.init();
// 设置邮件主题内容及收件人
mailUtil.setSubject(msg.getMessageTitle()); mailUtil.setSubject(msg.getMessageTitle());
mailUtil.setContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.valueOfDescription(msg.getMessageContentType())); mailUtil.setContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.valueOfDescription(msg.getMessageContentType()));
mailUtil.setBody(msg.getMessageContent()); mailUtil.setBody(msg.getMessageContent());
// 判断收件人类型 // 绑定附件信息
if (msg.getMessageReceiverType() != null) { if (msg.getFileAttachIdList() != null && msg.getFileAttachIdList().size() != 0) {
if (msg.getMessageReceiverType().intValue() == ImppEnumUtil.MESSAGE_RECEIVER_TYPE.URGENT.getValue()) { // 附件id
// 判断是否为系统紧急提示 微服注册状态提示 InputStream in = null;
mailUtil.setTo(RedisCacheTool.getSysConfigStrVal(PlatformConstWords.CONTACT_MAIL)); for (Long attachId : msg.getFileAttachIdList()) {
SysFile sysFile = sysFileService.getSysFileById(attachId);
try { try {
mailUtil.send(); in = fileService.downFile(sysFile);
} catch (Exception e) { mailUtil.addAttachment(sysFile.getFileOriginalName(), IOUtils.toByteArray(in));
saveSendErrorMsg(msg, RedisCacheTool.getSysConfigStrVal(PlatformConstWords.CONTACT_MAIL), e);
SysFileAttach sysFileAttach = new SysFileAttach();
sysFileAttach.setFileId(attachId);
sysFileAttach.setAttachSoftType(msg.getMessageSoftType());
sysFileAttach.setAttachSource(ImppEnumUtil.FILE_ATTACH_SOURCE.MAIL.getValue());
sysFileAttach.setFileNameRdd(sysFile.getFileOriginalName());
sysFileAttach.setFilePathRdd(sysFile.getFilePath());
sysFileAttachService.insertSysFileAttach(sysFileAttach);
}finally {
if(in != null) {
in.close();
}
} }
}
}
} else if (msg.getMessageReceiverType().intValue() == ImppEnumUtil.MESSAGE_RECEIVER_TYPE.EXTERNAL.getValue()) { // 判断收件人类型
if (msg.getMessageReceiverType() != null) {
if (msg.getMessageReceiverType() == ImppEnumUtil.MESSAGE_RECEIVER_TYPE.EXTERNAL.getValue()) {
//判断是否为外部邮件 //判断是否为外部邮件
mailUtil.setTo(StringUtils.split(msg.getMessageReceiversNameRdd(), ",")); mailUtil.setTo(StringUtils.split(msg.getMessageReceiversNameRdd(), ","));
try { try {
@ -96,15 +128,15 @@ public class MessageMailQueueReceiver {
saveSendErrorMsg(msg, RedisCacheTool.getSysConfigStrVal(PlatformConstWords.CONTACT_MAIL), e); saveSendErrorMsg(msg, RedisCacheTool.getSysConfigStrVal(PlatformConstWords.CONTACT_MAIL), e);
} }
} else if (msg.getMessageReceiverType().intValue() == ImppEnumUtil.MESSAGE_RECEIVER_TYPE.INTERNAL.getValue()) { } else if (msg.getMessageReceiverType() == ImppEnumUtil.MESSAGE_RECEIVER_TYPE.INTERNAL.getValue()) {
// 收件人信息 // 收件人信息
String[] messageReceiver = msg.getMessageReceiversId().split(","); String[] messageReceiver = msg.getMessageReceiversId().split(",");
SysRefUserMessage refUserMessage; SysRefUserMessage refUserMessage;
SysUser sysUser; SysUser sysUser;
for (int i = 0; i < messageReceiver.length; i++) { for (String receiver : messageReceiver) {
sysUser = sysUserService.getSysUserById(Long.parseLong(messageReceiver[i])); sysUser = sysUserService.getSysUserById(Long.parseLong(receiver));
refUserMessage = new SysRefUserMessage(); refUserMessage = new SysRefUserMessage();
refUserMessage.setMessageId(msg.getId()); refUserMessage.setMessageId(msg.getId());
@ -128,6 +160,8 @@ public class MessageMailQueueReceiver {
saveSendErrorMsg(msg, RedisCacheTool.getSysConfigStrVal(PlatformConstWords.CONTACT_MAIL), e); saveSendErrorMsg(msg, RedisCacheTool.getSysConfigStrVal(PlatformConstWords.CONTACT_MAIL), e);
} }
} }
mailUtil.cleanAttachmentList();
} }
} }

@ -1,9 +1,12 @@
package cn.estsh.i3plus.core.apiservice.util; package cn.estsh.i3plus.core.apiservice.util;
import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum; import cn.estsh.i3plus.platform.common.exception.ImppExceptionEnum;
import cn.estsh.i3plus.platform.common.tool.StringTool;
import cn.estsh.i3plus.platform.common.util.CommonConstWords; import cn.estsh.i3plus.platform.common.util.CommonConstWords;
import cn.estsh.i3plus.platform.common.util.FileContentTypeTool;
import cn.estsh.i3plus.platform.common.util.PlatformConstWords; import cn.estsh.i3plus.platform.common.util.PlatformConstWords;
import cn.estsh.i3plus.pojo.base.enumutil.CommonEnumUtil; 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.MailConfig;
import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder; import cn.estsh.impp.framework.boot.exception.ImppExceptionBuilder;
import cn.estsh.impp.framework.boot.util.ImppRedis; import cn.estsh.impp.framework.boot.util.ImppRedis;
@ -12,18 +15,19 @@ import com.sun.mail.smtp.SMTPAddressFailedException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.activation.FileDataSource;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.mail.Address; import javax.mail.*;
import javax.mail.AuthenticationFailedException; import javax.mail.internet.*;
import javax.mail.Message; import javax.mail.util.ByteArrayDataSource;
import javax.mail.MessagingException; import java.io.File;
import javax.mail.Session; import java.io.IOException;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeUtility;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties; import java.util.Properties;
/** /**
@ -52,6 +56,7 @@ public class MailUtil {
private String smtpUser = ""; private String smtpUser = "";
private String smtpPassword = ""; private String smtpPassword = "";
private boolean isAuthenticationSMTP = false; private boolean isAuthenticationSMTP = false;
private final List<BodyPart> attachmentList = new ArrayList<>();
@Resource(name = CommonConstWords.IMPP_REDIS_RES) @Resource(name = CommonConstWords.IMPP_REDIS_RES)
private ImppRedis redisRes; private ImppRedis redisRes;
@ -73,6 +78,7 @@ public class MailUtil {
this.smtpUser = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.MAIL_USER); this.smtpUser = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.MAIL_USER);
this.smtpPassword = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.MAIL_PASSWORD); this.smtpPassword = RedisCacheTool.getSysConfigStrVal(PlatformConstWords.MAIL_PASSWORD);
this.isAuthenticationSMTP = true; this.isAuthenticationSMTP = true;
this.attachmentList.clear();
return this; return this;
} catch (Exception e) { } catch (Exception e) {
LOGGER.error("邮箱配置初始化失败!", e.getMessage()); LOGGER.error("邮箱配置初始化失败!", e.getMessage());
@ -201,6 +207,49 @@ public class MailUtil {
} }
/** /**
*
* @param fileName
* @param attachmentByte
* @throws MessagingException
*/
public void addAttachment(String fileName, byte[] attachmentByte) throws MessagingException {
addAttachment(fileName, attachmentByte,
FileContentTypeTool.getContentType(StringTool.getStringFileSuffix(fileName, true)));
}
/**
*
* @param fileName
* @param attachmentByte
* @param contentType
* @throws MessagingException
*/
public void addAttachment(String fileName, byte[] attachmentByte,String contentType) throws MessagingException {
BodyPart attachmentBodyPart = new MimeBodyPart();
DataSource source = new ByteArrayDataSource(attachmentByte, contentType);
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(fileName);
attachmentList.add(attachmentBodyPart);
}
/**
*
* @param attachment
* @throws MessagingException
*/
public void addAttachment(File attachment) throws MessagingException {
BodyPart attachmentBodyPart = new MimeBodyPart();
DataSource source = new FileDataSource(attachment);
attachmentBodyPart.setDataHandler(new DataHandler(source));
attachmentBodyPart.setFileName(attachment.getName());
attachmentList.add(attachmentBodyPart);
}
public void cleanAttachmentList(){
attachmentList.clear();
}
/**
* *
*/ */
public void send() { public void send() {
@ -241,7 +290,23 @@ public class MailUtil {
// 消息主体内容 处理 // 消息主体内容 处理
this.content = this.content == null ? "" : this.content; this.content = this.content == null ? "" : this.content;
msg.setContent(this.content, this.contentType); // 判断是否存在附件
if (!attachmentList.isEmpty()) {
// 添加邮件的各个部分内容,包括文本内容和附件
Multipart multipart = new MimeMultipart();
// 添加邮件正文
BodyPart contentPart = new MimeBodyPart();
contentPart.setContent(content, this.contentType);
multipart.addBodyPart(contentPart);
for (BodyPart bodyPart : attachmentList) {
multipart.addBodyPart(bodyPart);
}
msg.setContent(multipart);
} else {
msg.setContent(this.content, this.contentType);
}
msg.saveChanges(); msg.saveChanges();
if (this.isAuthenticationSMTP) { if (this.isAuthenticationSMTP) {
@ -255,7 +320,7 @@ public class MailUtil {
LOGGER.info("邮件发送成功"); LOGGER.info("邮件发送成功");
} catch (SMTPAddressFailedException e) { } catch (SMTPAddressFailedException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error("邮件发送异常",e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_RECIPIENT_NOT_EXIST.getCode())
@ -263,7 +328,7 @@ public class MailUtil {
.setErrorSolution("请重新设置收件人") .setErrorSolution("请重新设置收件人")
.build(); .build();
} catch (AuthenticationFailedException e) { } catch (AuthenticationFailedException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error("邮件发送异常",e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_LOGIN_PASS_ERROR.getCode())
@ -271,7 +336,7 @@ public class MailUtil {
.setErrorSolution("请重新设置账号或密码") .setErrorSolution("请重新设置账号或密码")
.build(); .build();
} catch (MessagingException e) { } catch (MessagingException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error("邮件发送异常",e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())
@ -279,7 +344,7 @@ public class MailUtil {
.setErrorSolution("请重新设置邮件服务器地址或端口") .setErrorSolution("请重新设置邮件服务器地址或端口")
.build(); .build();
} catch (UnsupportedEncodingException e) { } catch (UnsupportedEncodingException e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error("邮件发送异常",e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())
@ -287,7 +352,7 @@ public class MailUtil {
.setErrorSolution("请重新设置邮件服务器地址或端口") .setErrorSolution("请重新设置邮件服务器地址或端口")
.build(); .build();
} catch (Exception e) { } catch (Exception e) {
LOGGER.error(e.getClass() + "\t" + e.getMessage()); LOGGER.error("邮件发送异常",e);
throw ImppExceptionBuilder.newInstance() throw ImppExceptionBuilder.newInstance()
.setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode()) .setSystemID(CommonEnumUtil.SOFT_TYPE.IMPP.getCode())
.setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode()) .setErrorCode(ImppExceptionEnum.MAIL_SERVER_CONFIG_ERROR.getCode())
@ -296,4 +361,25 @@ public class MailUtil {
.build(); .build();
} }
} }
public static void main(String[] args) throws IOException, MessagingException {
MailConfig mailConfig = new MailConfig();
mailConfig.setMailSwitch(1);
mailConfig.setMailHost("smtphm.qiye.163.com");
mailConfig.setMailPort(25);
mailConfig.setMailNick("impp-test@estsh.com");
mailConfig.setMailUser("impp-test@estsh.com");
mailConfig.setMailPassword("Aa135790");
MailUtil mailUtil = new MailUtil();
mailUtil.init(mailConfig);
mailUtil.setNick("yunhao");
mailUtil.setTo("yunhaok@163.com");
mailUtil.setContentType(ImppEnumUtil.MESSAGE_TYPE_CONTENT.TEXT.getDescription());
mailUtil.setSubject("test");
mailUtil.setBody("666");
File file = new File("C:\\Users\\yunha\\Desktop\\miss_file (2).txt");
mailUtil.addAttachment(file);
mailUtil.send();
}
} }

Loading…
Cancel
Save