工作组变更
This commit is contained in:
+35
-7
@@ -1,16 +1,22 @@
|
||||
package com.jero.modules.message.handle.impl;
|
||||
|
||||
import com.jero.common.exception.JeroBootException;
|
||||
import com.jero.common.util.SpringContextUtils;
|
||||
import com.jero.common.util.oConvertUtils;
|
||||
import com.jero.config.StaticConfig;
|
||||
import com.jero.modules.message.handle.ISendMsgHandle;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.core.io.FileSystemResource;
|
||||
import org.springframework.mail.javamail.JavaMailSender;
|
||||
import org.springframework.mail.javamail.MimeMessageHelper;
|
||||
import javax.mail.MessagingException;
|
||||
import javax.mail.internet.MimeMessage;
|
||||
import java.io.File;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
@@ -18,6 +24,9 @@ import java.util.List;
|
||||
public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
static String emailFrom;
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
public static void setEmailFrom(String emailFrom) {
|
||||
EmailSendMsgHandle.emailFrom = emailFrom;
|
||||
}
|
||||
@@ -47,10 +56,17 @@ public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
|
||||
}
|
||||
|
||||
|
||||
//带附件发送邮件,多人多邮件;
|
||||
|
||||
public void SendMsgAndFile(String es_receiver, String es_title, String es_content, List<String> fileList ) {
|
||||
/**
|
||||
* @Description 带附件发送邮件,多人多邮件
|
||||
* @Param es_receiver 接收人邮箱
|
||||
* @Param es_title 标题
|
||||
* @Param es_content 内容
|
||||
* @Param fileList 文件集合
|
||||
* @Param path 文件路径
|
||||
* @Return
|
||||
* @Exception
|
||||
*/
|
||||
public void SendMsgAndFile(String es_receiver, String es_title, String es_content, List<String> fileList) {
|
||||
JavaMailSender mailSender = (JavaMailSender) SpringContextUtils.getBean("mailSender");
|
||||
MimeMessage message = mailSender.createMimeMessage();
|
||||
MimeMessageHelper helper = null;
|
||||
@@ -59,6 +75,19 @@ public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
StaticConfig staticConfig = SpringContextUtils.getBean(StaticConfig.class);
|
||||
setEmailFrom(staticConfig.getEmailFrom());
|
||||
}
|
||||
if(CollectionUtils.isEmpty(fileList)){
|
||||
throw new JeroBootException("附件不能为空!");
|
||||
}
|
||||
// 验证文件是否存在
|
||||
fileList.forEach(p->{
|
||||
if(StringUtils.isBlank(p)){
|
||||
return;
|
||||
}
|
||||
File file = new File(p);
|
||||
if(!file.exists()){
|
||||
throw new JeroBootException("附件不存在!");
|
||||
}
|
||||
});
|
||||
//update-end-author:taoyan date:20200811 for:配置类数据获取
|
||||
try {
|
||||
ArrayList<String> mailList = new ArrayList<>(Arrays.asList(es_receiver.split(",")));
|
||||
@@ -72,16 +101,15 @@ public class EmailSendMsgHandle implements ISendMsgHandle {
|
||||
helper.setText(es_content, true);
|
||||
for(String file :fileList) {
|
||||
if(!StringUtils.isBlank(file)) {
|
||||
FileSystemResource filePath = new FileSystemResource(new File("D:\\opt\\upFiles" + "\\" + file));
|
||||
FileSystemResource filePath = new FileSystemResource(new File(file));
|
||||
helper.addAttachment(file, filePath);
|
||||
}
|
||||
}
|
||||
mailSender.send(message);
|
||||
}
|
||||
}
|
||||
} catch (MessagingException e) {
|
||||
}catch (MessagingException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
+14
-2
@@ -999,8 +999,20 @@ public class SysBaseApiImpl implements ISysBaseAPI {
|
||||
*/
|
||||
@Override
|
||||
public void sendEmailMsg(String email, String title, String content) {
|
||||
EmailSendMsgHandle emailHandle=new EmailSendMsgHandle();
|
||||
emailHandle.SendMsg(email, title, content);
|
||||
EmailSendMsgHandle emailHandle=new EmailSendMsgHandle();
|
||||
emailHandle.SendMsg(email, title, content);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送邮件+ 附件消息
|
||||
* @param email
|
||||
* @param title
|
||||
* @param content
|
||||
*/
|
||||
@Override
|
||||
public void sendEmailMsgAndFile(String email, String title, String content,List<String> list) {
|
||||
EmailSendMsgHandle emailHandle=new EmailSendMsgHandle();
|
||||
emailHandle.SendMsgAndFile(email, title, content,list);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user