|
|
@@ -1,5 +1,12 @@
|
|
|
package com.goafanti.common.utils;
|
|
|
|
|
|
+import com.goafanti.common.bo.EmailBo;
|
|
|
+import com.sun.mail.util.MailSSLSocketFactory;
|
|
|
+
|
|
|
+import javax.mail.*;
|
|
|
+import javax.mail.internet.InternetAddress;
|
|
|
+import javax.mail.internet.MimeMessage;
|
|
|
+import javax.mail.internet.MimeUtility;
|
|
|
import java.io.UnsupportedEncodingException;
|
|
|
import java.security.GeneralSecurityException;
|
|
|
import java.util.Date;
|
|
|
@@ -7,20 +14,6 @@ import java.util.Properties;
|
|
|
import java.util.regex.Matcher;
|
|
|
import java.util.regex.Pattern;
|
|
|
|
|
|
-import javax.mail.Authenticator;
|
|
|
-import javax.mail.Message;
|
|
|
-import javax.mail.MessagingException;
|
|
|
-import javax.mail.PasswordAuthentication;
|
|
|
-import javax.mail.Session;
|
|
|
-import javax.mail.Transport;
|
|
|
-import javax.mail.internet.InternetAddress;
|
|
|
-import javax.mail.internet.MimeMessage;
|
|
|
-import javax.mail.internet.MimeUtility;
|
|
|
-
|
|
|
-
|
|
|
-import com.goafanti.common.bo.EmailBo;
|
|
|
-import com.sun.mail.util.MailSSLSocketFactory;
|
|
|
-
|
|
|
public class SendEmailUtil {
|
|
|
private static Session session;
|
|
|
private static volatile SendEmailUtil singleton;
|
|
|
@@ -62,6 +55,7 @@ public class SendEmailUtil {
|
|
|
props.setProperty("mail.smtp.socketFactory.fallback", "false");// 注意是字符串的true,不是boolean类型的true
|
|
|
// 这一套是465端口
|
|
|
props.setProperty("mail.smtp.host", HOST);// 设置服务器地址
|
|
|
+ props.setProperty("mail.smtp.ssl.protocols", "TLSv1.2");
|
|
|
props.setProperty("mail.smtp.socketFactory.class", SSL_FACTORY);// 设置协议
|
|
|
props.setProperty("mail.smtp.port", PORT);// 设置端口
|
|
|
props.put("mail.smtp.auth", "true");// 注意是字符串的true,不是boolean类型的true
|
|
|
@@ -86,7 +80,7 @@ public class SendEmailUtil {
|
|
|
*/
|
|
|
public void send(EmailBo emailBo)
|
|
|
throws MessagingException, UnsupportedEncodingException {
|
|
|
- // Session session = getSession();
|
|
|
+// Session session = getSession();
|
|
|
// Instantiate a message
|
|
|
Message msg = new MimeMessage(session);
|
|
|
// Set message attributes
|
|
|
@@ -149,13 +143,13 @@ public class SendEmailUtil {
|
|
|
|
|
|
|
|
|
|
|
|
-// public static void main(String[] args) {
|
|
|
-// EmailBo emailBo = new EmailBo( "专利提醒失败", "312518615@qq.com", "超管", "平台", "系统", "专利提醒失败");
|
|
|
-// try {
|
|
|
-// SendEmailUtil.getInstance().send(emailBo);
|
|
|
-// } catch (UnsupportedEncodingException | MessagingException e) {
|
|
|
-// e.printStackTrace();
|
|
|
-// }
|
|
|
-// }
|
|
|
+ public static void main(String[] args) {
|
|
|
+ EmailBo emailBo = new EmailBo( "专利提醒失败", "anderx@dingtalk.com", "平台", "系统", "专利提醒失败");
|
|
|
+ try {
|
|
|
+ SendEmailUtil.getInstance().send(emailBo);
|
|
|
+ } catch (UnsupportedEncodingException | MessagingException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
}
|