From 368260a4b3edef2b1a9d5fd8ea7fc05eee291ae1 Mon Sep 17 00:00:00 2001 From: caryyu <343194291@qq.com> Date: Fri, 20 Apr 2018 17:56:19 +0800 Subject: [PATCH] Solve this: https://github.com/xuxueli/xxl-job/issues/359 --- .../com/xxl/job/admin/core/conf/XxlJobAdminConfig.java | 7 +++++++ .../java/com/xxl/job/admin/core/util/MailUtil.java | 10 ++++++++-- .../src/main/resources/xxl-job-admin.properties | 1 + 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java index adcd321c..ba41d716 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java @@ -27,6 +27,9 @@ public class XxlJobAdminConfig implements InitializingBean{ @Value("${xxl.job.mail.port}") private String mailPort; + @Value("${xxl.job.mail.ssl}") + private boolean mailSSL; + @Value("${xxl.job.mail.username}") private String mailUsername; @@ -54,6 +57,10 @@ public class XxlJobAdminConfig implements InitializingBean{ return mailPort; } + public boolean isMailSSL() { + return mailSSL; + } + public String getMailUsername() { return mailUsername; } diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java index 8e469bc7..d046e200 100644 --- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java +++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java @@ -35,8 +35,14 @@ public class MailUtil { //email.setSSL(true); email.setHostName(XxlJobAdminConfig.getAdminConfig().getMailHost()); - email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort())); - //email.setSslSmtpPort(port); + + if (XxlJobAdminConfig.getAdminConfig().isMailSSL()) { + email.setSslSmtpPort(XxlJobAdminConfig.getAdminConfig().getMailPort()); + email.setSSLOnConnect(true); + } else { + email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort())); + } + email.setAuthenticator(new DefaultAuthenticator(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailPassword())); email.setCharset(Charset.defaultCharset().name()); diff --git a/xxl-job-admin/src/main/resources/xxl-job-admin.properties b/xxl-job-admin/src/main/resources/xxl-job-admin.properties index f038062c..b16ca1a1 100644 --- a/xxl-job-admin/src/main/resources/xxl-job-admin.properties +++ b/xxl-job-admin/src/main/resources/xxl-job-admin.properties @@ -7,6 +7,7 @@ xxl.job.db.password=root_pwd ### xxl-job email xxl.job.mail.host=smtp.163.com xxl.job.mail.port=25 +xxl.job.mail.ssl=false xxl.job.mail.username=ovono802302@163.com xxl.job.mail.password=asdfzxcv xxl.job.mail.sendNick=《任务调度平台XXL-JOB》