Browse Source

Merge pull request #292 from yangqinlong/dev

启用SSL的邮箱发送邮件
pull/2/head
乔占卫 6 years ago committed by GitHub
parent
commit
8d9f2f441e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java
  2. 9
      escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java
  3. 3
      escheduler-alert/src/main/resources/alert.properties

2
escheduler-alert/src/main/java/cn/escheduler/alert/utils/Constants.java

@ -59,6 +59,8 @@ public class Constants {
public static final String MAIL_SMTP_STARTTLS_ENABLE = "mail.smtp.starttls.enable";
public static final String MAIL_SMTP_SSL_ENABLE = "mail.smtp.ssl.enable";
public static final String TEXT_HTML_CHARSET_UTF_8 = "text/html;charset=utf-8";
public static final String STRING_TRUE = "true";

9
escheduler-alert/src/main/java/cn/escheduler/alert/utils/MailUtils.java

@ -35,6 +35,7 @@ import javax.mail.internet.*;
import java.io.*;
import java.util.*;
import static cn.escheduler.alert.utils.PropertyUtils.getBoolean;
import static cn.escheduler.alert.utils.PropertyUtils.getInt;
import static cn.escheduler.alert.utils.PropertyUtils.getString;
@ -56,6 +57,10 @@ public class MailUtils {
public static final String mailPasswd = getString(Constants.MAIL_PASSWD);
public static final Boolean mailUseStartTLS = getBoolean(Constants.MAIL_SMTP_STARTTLS_ENABLE);
public static final Boolean mailUseSSL = getBoolean(Constants.MAIL_SMTP_SSL_ENABLE);
public static final String xlsFilePath = getString(Constants.XLS_FILE_PATH);
private static Template MAIL_TEMPLATE;
@ -122,7 +127,9 @@ public class MailUtils {
//set charset
email.setCharset(Constants.UTF_8);
// TLS verification
email.setTLS(true);
email.setTLS(mailUseStartTLS);
// SSL verification
email.setSSL(mailUseSSL);
if (CollectionUtils.isNotEmpty(receivers)){
// receivers mail
for (String receiver : receivers) {

3
escheduler-alert/src/main/resources/alert.properties

@ -8,6 +8,9 @@ mail.server.port=25
mail.sender=xxxxxxx
mail.passwd=xxxxxxx
mail.smtp.starttls.enable=false
mail.smtp.ssl.enable=true
#xls file path,need create if not exist
xls.file.path=/opt/xls

Loading…
Cancel
Save