|
|
@@ -22,6 +22,14 @@ import com.goafanti.common.bo.EmailBo;
|
|
|
import com.sun.mail.util.MailSSLSocketFactory;
|
|
|
|
|
|
public class SendEmailUtil {
|
|
|
+ //是否发邮件标识 0否 1是
|
|
|
+ private Integer emailFlag = 0;
|
|
|
+ public static final String HOST = "smtp.163.com";
|
|
|
+ public static final String PORT = "465";
|
|
|
+ public static final String AUTH_USER_NICKNAME = "湖南科德信息咨询有限公司";
|
|
|
+ public static final String FROM = "13875952633@163.com";// 发件人的email
|
|
|
+ public static final String PWD = "kede2018";// 发件人密码
|
|
|
+ public static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
|
|
|
private static Session session;
|
|
|
private static volatile SendEmailUtil singleton;
|
|
|
private SendEmailUtil() {}
|
|
|
@@ -36,12 +44,7 @@ public class SendEmailUtil {
|
|
|
}
|
|
|
return singleton;
|
|
|
}
|
|
|
- public static final String HOST = "smtp.163.com";
|
|
|
- public static final String PORT = "465";
|
|
|
- public static final String AUTH_USER_NICKNAME = "湖南科德信息咨询有限公司";
|
|
|
- public static final String FROM = "13875952633@163.com";// 发件人的email
|
|
|
- public static final String PWD = "kede2018";// 发件人密码
|
|
|
- public static final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
@@ -84,24 +87,24 @@ public class SendEmailUtil {
|
|
|
* @throws MessagingException
|
|
|
* @throws UnsupportedEncodingException
|
|
|
*/
|
|
|
- public void send(EmailBo emailBo)
|
|
|
- throws MessagingException, UnsupportedEncodingException {
|
|
|
- // Session session = getSession();
|
|
|
- // Instantiate a message
|
|
|
- Message msg = new MimeMessage(session);
|
|
|
- // Set message attributes
|
|
|
- msg.setFrom(new InternetAddress(MimeUtility.encodeText(AUTH_USER_NICKNAME) +"<" + FROM + ">"));
|
|
|
+ public void send(EmailBo emailBo) throws MessagingException, UnsupportedEncodingException {
|
|
|
+ if (emailFlag==1) {
|
|
|
+ // Instantiate a message
|
|
|
+ Message msg = new MimeMessage(session);
|
|
|
+ // Set message attributes
|
|
|
+ msg.setFrom(new InternetAddress(MimeUtility.encodeText(AUTH_USER_NICKNAME) +"<" + FROM + ">"));
|
|
|
// msg.setFrom(new InternetAddress(FROM));
|
|
|
- String[] adds = emailBo.getAddress().split(",");
|
|
|
- String[] ees = emailBo.getAddressee().split(",");
|
|
|
- for (int i = 0; i < adds.length; i++) {
|
|
|
- InternetAddress internetAddress = new InternetAddress(adds[i]);
|
|
|
- msg.setRecipient(Message.RecipientType.TO, internetAddress);
|
|
|
- msg.setSubject(emailBo.getSubject());
|
|
|
- msg.setSentDate(new Date());
|
|
|
- msg.setContent(emailBo.format(ees[i]), "text/html;charset=utf-8");
|
|
|
- // Send the message
|
|
|
- Transport.send(msg);
|
|
|
+ String[] adds = emailBo.getAddress().split(",");
|
|
|
+ String[] ees = emailBo.getAddressee().split(",");
|
|
|
+ for (int i = 0; i < adds.length; i++) {
|
|
|
+ InternetAddress internetAddress = new InternetAddress(adds[i]);
|
|
|
+ msg.setRecipient(Message.RecipientType.TO, internetAddress);
|
|
|
+ msg.setSubject(emailBo.getSubject());
|
|
|
+ msg.setSentDate(new Date());
|
|
|
+ msg.setContent(emailBo.format(ees[i]), "text/html;charset=utf-8");
|
|
|
+ // Send the message
|
|
|
+ Transport.send(msg);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -111,26 +114,22 @@ public class SendEmailUtil {
|
|
|
* @throws MessagingException
|
|
|
* @throws UnsupportedEncodingException
|
|
|
*/
|
|
|
- public void patentSend(EmailBo emailBo)
|
|
|
- throws MessagingException, UnsupportedEncodingException {
|
|
|
- // Session session = getSession();
|
|
|
- // Instantiate a message
|
|
|
- Message msg = new MimeMessage(session);
|
|
|
-
|
|
|
- // Set message attributes
|
|
|
- msg.setFrom(new InternetAddress(MimeUtility.encodeText(AUTH_USER_NICKNAME) +"<" + FROM + ">"));
|
|
|
- emailBo.SetEnd("");
|
|
|
-// msg.setFrom(new InternetAddress(FROM));
|
|
|
- String[] adds = emailBo.getAddress().split(",");
|
|
|
-// String[] ees = emailBo.getAddressee().split(",");
|
|
|
- for (int i = 0; i < adds.length; i++) {
|
|
|
- InternetAddress internetAddress = new InternetAddress(adds[i]);
|
|
|
- msg.setRecipient(Message.RecipientType.TO, internetAddress);
|
|
|
- msg.setSubject(emailBo.getSubject());
|
|
|
- msg.setSentDate(new Date());
|
|
|
- msg.setContent(emailBo.getContent(), "text/html;charset=utf-8");
|
|
|
- // Send the message
|
|
|
- Transport.send(msg);
|
|
|
+ public void patentSend(EmailBo emailBo) throws MessagingException, UnsupportedEncodingException {
|
|
|
+ if (emailFlag==1) {
|
|
|
+ Message msg = new MimeMessage(session);
|
|
|
+ // Set message attributes
|
|
|
+ msg.setFrom(new InternetAddress(MimeUtility.encodeText(AUTH_USER_NICKNAME) +"<" + FROM + ">"));
|
|
|
+ emailBo.SetEnd("");
|
|
|
+ String[] adds = emailBo.getAddress().split(",");
|
|
|
+ for (int i = 0; i < adds.length; i++) {
|
|
|
+ InternetAddress internetAddress = new InternetAddress(adds[i]);
|
|
|
+ msg.setRecipient(Message.RecipientType.TO, internetAddress);
|
|
|
+ msg.setSubject(emailBo.getSubject());
|
|
|
+ msg.setSentDate(new Date());
|
|
|
+ msg.setContent(emailBo.getContent(), "text/html;charset=utf-8");
|
|
|
+ // Send the message
|
|
|
+ Transport.send(msg);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|