|
@@ -16,6 +16,8 @@ import javax.annotation.Resource;
|
|
|
import javax.mail.MessagingException;
|
|
|
import javax.mail.internet.MimeMessage;
|
|
|
import java.io.File;
|
|
|
+import java.io.UnsupportedEncodingException;
|
|
|
+import java.util.Base64;
|
|
|
|
|
|
/**
|
|
|
* @Description:
|
|
@@ -208,11 +210,23 @@ public class IMailServiceImpl implements IMailService {
|
|
|
logger.info("filePath::::::::::" + filePath);
|
|
|
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
|
|
|
logger.info("fileName::::::::::" + fileName);
|
|
|
- helper.addAttachment(fileName, file);
|
|
|
+ // 使用UTF-8编码将文件名转换为字节数组
|
|
|
+ byte[] fileNameBytes = fileName.getBytes("UTF-8");
|
|
|
+
|
|
|
+ // 对字节数组进行Base64编码
|
|
|
+ String base64FileName = Base64.getEncoder().encodeToString(fileNameBytes);
|
|
|
+
|
|
|
+ // 构造Base64编码后的附件名
|
|
|
+ String encodedAttachmentName = "=?UTF-8?B?" + base64FileName + "?=";
|
|
|
+
|
|
|
+ System.out.println("原始附件名: " + fileName);
|
|
|
+ System.out.println("Base64编码后的附件名: " + encodedAttachmentName);
|
|
|
+
|
|
|
+ helper.addAttachment(encodedAttachmentName, file);
|
|
|
mailSender.send(message);
|
|
|
//日志信息
|
|
|
logger.info("邮件已经发送。");
|
|
|
- } catch (MessagingException e) {
|
|
|
+ } catch (MessagingException | UnsupportedEncodingException e) {
|
|
|
logger.error("发送邮件时发生异常!", e);
|
|
|
}
|
|
|
}
|