|
@@ -22,6 +22,7 @@ import org.slf4j.LoggerFactory;
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
import org.springframework.mail.javamail.JavaMailSender;
|
|
|
|
|
|
import java.io.File;
|
|
import java.io.File;
|
|
|
|
+import java.io.IOException;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Files;
|
|
import java.nio.file.Paths;
|
|
import java.nio.file.Paths;
|
|
import java.util.*;
|
|
import java.util.*;
|
|
@@ -172,8 +173,16 @@ public class EmailUtil {
|
|
saveFile.getParentFile().setExecutable(true);
|
|
saveFile.getParentFile().setExecutable(true);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+ //获取邮件编码
|
|
|
|
+ String contentType = part.getContentType();
|
|
|
|
+ String html = partContent.toString();
|
|
try{
|
|
try{
|
|
- FileUtils.write(new File(savePath), partContent.toString());
|
|
|
|
|
|
+ if(contentType.indexOf("charset=") != -1){
|
|
|
|
+ contentType = contentType.substring(contentType.indexOf("charset=")+8,contentType.length());
|
|
|
|
+ html = html.replace("charset="+contentType.toLowerCase(),"charset=UTF-8");
|
|
|
|
+ html = html.replace("charset="+contentType.toUpperCase(),"charset=UTF-8");
|
|
|
|
+ }
|
|
|
|
+ FileUtils.write(new File(savePath), html);
|
|
}catch (Exception e){
|
|
}catch (Exception e){
|
|
logger.error(e.getMessage(),e);
|
|
logger.error(e.getMessage(),e);
|
|
}
|
|
}
|
|
@@ -314,8 +323,6 @@ public class EmailUtil {
|
|
properties.setProperty("mail.smtp.socketFactory.port", mailboxInfoDTO.getPort());
|
|
properties.setProperty("mail.smtp.socketFactory.port", mailboxInfoDTO.getPort());
|
|
properties.put("mail.smtp.ssl.enable", true);
|
|
properties.put("mail.smtp.ssl.enable", true);
|
|
// 根据邮件的会话属性构造一个发送邮件的Session,
|
|
// 根据邮件的会话属性构造一个发送邮件的Session,
|
|
- //这里需要注意的是用户名那里不能加后缀,否则便不是用户名了
|
|
|
|
- //还需要注意的是,这里的密码不是正常使用邮箱的登陆密码,而是客户端生成的另一个专门的授权码
|
|
|
|
JakartaUserPassAuthenticator authenticator = new JakartaUserPassAuthenticator(mailboxInfoDTO.getAccount(), mailboxInfoDTO.getPassword());
|
|
JakartaUserPassAuthenticator authenticator = new JakartaUserPassAuthenticator(mailboxInfoDTO.getAccount(), mailboxInfoDTO.getPassword());
|
|
Session session = Session.getInstance(properties, authenticator);
|
|
Session session = Session.getInstance(properties, authenticator);
|
|
return session;
|
|
return session;
|