|
@@ -1,7 +1,5 @@
|
|
|
package com.ruoyi.zzb.common.service;
|
|
|
|
|
|
-import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
|
|
-import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
import com.ruoyi.common.annotation.DataSource;
|
|
|
import com.ruoyi.common.enums.DataSourceType;
|
|
|
import com.ruoyi.common.utils.file.FileUploadUtils;
|
|
@@ -12,17 +10,17 @@ import com.ruoyi.zzb.common.utils.CommonUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
-import org.springframework.core.io.FileSystemResource;
|
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
import org.springframework.mail.javamail.MimeMessageHelper;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
-
|
|
|
import javax.mail.MessagingException;
|
|
|
import javax.mail.internet.MimeMessage;
|
|
|
+import javax.mail.internet.MimeUtility;
|
|
|
import java.io.File;
|
|
|
import java.io.IOException;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
@@ -48,18 +46,28 @@ public class BaseService {
|
|
|
* @param subject
|
|
|
* @param text
|
|
|
* @param attachmentPath
|
|
|
+ * @param files
|
|
|
* @throws MessagingException
|
|
|
+ * @throws UnsupportedEncodingException
|
|
|
*/
|
|
|
- public void sendEmail(String to, String subject, String text, String attachmentPath) throws MessagingException {
|
|
|
+ public void sendEmail(String to, String subject, String text, String attachmentPath, File[] files) throws MessagingException, UnsupportedEncodingException {
|
|
|
MimeMessage message = mailSender.createMimeMessage();
|
|
|
+ //解决附件文件名称过长乱码问题
|
|
|
+ System.setProperty("mail.mime.splitlongparameters","false");
|
|
|
MimeMessageHelper helper = new MimeMessageHelper(message, true);
|
|
|
helper.setFrom(from);
|
|
|
helper.setTo(to);
|
|
|
helper.setSubject(subject);
|
|
|
helper.setText(text);
|
|
|
- FileSystemResource file = new FileSystemResource(new File(attachmentPath));
|
|
|
- // 添加附件
|
|
|
- helper.addAttachment(file.getFilename(), file);
|
|
|
+ // 添加附件(多个)
|
|
|
+ if(files != null && files.length > 0) {
|
|
|
+ for (File file : files) {
|
|
|
+ helper.addAttachment(MimeUtility.encodeWord(file.getName(), "utf-8", "B"), file);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /*FileSystemResource file = new FileSystemResource(new File(attachmentPath));
|
|
|
+ // 添加附件(单个)
|
|
|
+ helper.addAttachment(file.getFilename(), file);*/
|
|
|
mailSender.send(message);
|
|
|
}
|
|
|
|