|
|
@ -33,6 +33,7 @@ import org.springframework.util.ResourceUtils; |
|
|
|
import javax.mail.*; |
|
|
|
import javax.mail.*; |
|
|
|
import javax.mail.internet.*; |
|
|
|
import javax.mail.internet.*; |
|
|
|
import java.io.*; |
|
|
|
import java.io.*; |
|
|
|
|
|
|
|
import java.security.Security; |
|
|
|
import java.util.*; |
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
import static cn.escheduler.alert.utils.PropertyUtils.getInt; |
|
|
|
import static cn.escheduler.alert.utils.PropertyUtils.getInt; |
|
|
@ -58,6 +59,10 @@ public class MailUtils { |
|
|
|
|
|
|
|
|
|
|
|
public static final String xlsFilePath = getString(Constants.XLS_FILE_PATH); |
|
|
|
public static final String xlsFilePath = getString(Constants.XLS_FILE_PATH); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String starttlsEnable = getString(Constants.MAIL_SMTP_STARTTLS_ENABLE); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public static final String sslEnable = getString(Constants.MAIL_SMTP_SSL_ENABLE); |
|
|
|
|
|
|
|
|
|
|
|
private static Template MAIL_TEMPLATE; |
|
|
|
private static Template MAIL_TEMPLATE; |
|
|
|
|
|
|
|
|
|
|
|
static { |
|
|
|
static { |
|
|
@ -122,7 +127,10 @@ public class MailUtils { |
|
|
|
//set charset
|
|
|
|
//set charset
|
|
|
|
email.setCharset(Constants.UTF_8); |
|
|
|
email.setCharset(Constants.UTF_8); |
|
|
|
// TLS verification
|
|
|
|
// TLS verification
|
|
|
|
email.setTLS(true); |
|
|
|
email.setTLS(Boolean.valueOf(starttlsEnable)); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// SSL verification
|
|
|
|
|
|
|
|
email.setSSL(Boolean.valueOf(sslEnable)); |
|
|
|
if (CollectionUtils.isNotEmpty(receivers)){ |
|
|
|
if (CollectionUtils.isNotEmpty(receivers)){ |
|
|
|
// receivers mail
|
|
|
|
// receivers mail
|
|
|
|
for (String receiver : receivers) { |
|
|
|
for (String receiver : receivers) { |
|
|
@ -269,11 +277,15 @@ public class MailUtils { |
|
|
|
* @throws MessagingException |
|
|
|
* @throws MessagingException |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private static MimeMessage getMimeMessage(Collection<String> receivers) throws MessagingException { |
|
|
|
private static MimeMessage getMimeMessage(Collection<String> receivers) throws MessagingException { |
|
|
|
|
|
|
|
// Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());
|
|
|
|
|
|
|
|
// final String SSL_FACTORY = "javax.net.ssl.SSLSocketFactory";
|
|
|
|
|
|
|
|
|
|
|
|
Properties props = new Properties(); |
|
|
|
Properties props = new Properties(); |
|
|
|
props.setProperty(Constants.MAIL_HOST, mailServerHost); |
|
|
|
props.setProperty(Constants.MAIL_HOST, mailServerHost); |
|
|
|
props.setProperty(Constants.MAIL_SMTP_AUTH, Constants.STRING_TRUE); |
|
|
|
props.setProperty(Constants.MAIL_SMTP_AUTH, Constants.STRING_TRUE); |
|
|
|
props.setProperty(Constants.MAIL_TRANSPORT_PROTOCOL, mailProtocol); |
|
|
|
props.setProperty(Constants.MAIL_TRANSPORT_PROTOCOL, mailProtocol); |
|
|
|
props.setProperty(Constants.MAIL_SMTP_STARTTLS_ENABLE, Constants.STRING_TRUE); |
|
|
|
props.setProperty(Constants.MAIL_SMTP_STARTTLS_ENABLE, starttlsEnable); |
|
|
|
|
|
|
|
props.setProperty("mail.smtp.ssl.enable", sslEnable); |
|
|
|
Authenticator auth = new Authenticator() { |
|
|
|
Authenticator auth = new Authenticator() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
protected PasswordAuthentication getPasswordAuthentication() { |
|
|
|
protected PasswordAuthentication getPasswordAuthentication() { |
|
|
|