|
@@ -261,10 +261,10 @@ public class EmailUtil {
|
|
|
return props;
|
|
|
}
|
|
|
|
|
|
- public static void senEmail(MailboxInfoDTO mailboxInfoDTO, String emails, File file, JavaMailSender javaMailSender,String htmlText) throws Exception {
|
|
|
+ public static void senEmail(MailboxInfoDTO mailboxInfoDTO, String emails, File file,String htmlText) throws Exception {
|
|
|
logger.info("send email begin .........");
|
|
|
// 根据Session 构建邮件信息
|
|
|
- MimeMessage message = javaMailSender.createMimeMessage();
|
|
|
+ MimeMessage message = new MimeMessage(getSession(mailboxInfoDTO));
|
|
|
// 创建邮件发送者地址
|
|
|
Address from = new InternetAddress(mailboxInfoDTO.getAccount());
|
|
|
String[] emailArr = emails.split(";");
|
|
@@ -300,6 +300,28 @@ public class EmailUtil {
|
|
|
// 保存邮件
|
|
|
message.saveChanges();
|
|
|
// 发送邮件
|
|
|
- javaMailSender.send(message);
|
|
|
+ Transport.send(message);
|
|
|
+ }
|
|
|
+ public static Session getSession(MailboxInfoDTO mailboxInfoDTO){
|
|
|
+ try{
|
|
|
+ final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
|
|
|
+ Properties properties = new Properties();
|
|
|
+ properties.put("mail.smtp.host", mailboxInfoDTO.getHost());
|
|
|
+ properties.put("mail.smtp.auth", true);
|
|
|
+ properties.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);
|
|
|
+ properties.setProperty("mail.smtp.socketFactory.fallback", "false");
|
|
|
+ properties.setProperty("mail.smtp.port", mailboxInfoDTO.getPort());
|
|
|
+ properties.setProperty("mail.smtp.socketFactory.port", mailboxInfoDTO.getPort());
|
|
|
+ properties.put("mail.smtp.ssl.enable", true);
|
|
|
+ // 根据邮件的会话属性构造一个发送邮件的Session,
|
|
|
+ //这里需要注意的是用户名那里不能加后缀,否则便不是用户名了
|
|
|
+ //还需要注意的是,这里的密码不是正常使用邮箱的登陆密码,而是客户端生成的另一个专门的授权码
|
|
|
+ JakartaUserPassAuthenticator authenticator = new JakartaUserPassAuthenticator(mailboxInfoDTO.getAccount(), mailboxInfoDTO.getPassword());
|
|
|
+ Session session = Session.getInstance(properties, authenticator);
|
|
|
+ return session;
|
|
|
+ }catch(Exception e){
|
|
|
+ logger.error("getSession : "+e.getMessage());
|
|
|
+ }
|
|
|
+ return null;
|
|
|
}
|
|
|
}
|