Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

报警邮件是否使用ssl方式可配置 #17

Merged
merged 1 commit into from
Jun 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/main/java/com/taobao/yugong/common/alarm/MailAlarmService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,19 @@

/**
* 发送邮件进行报警
*
*
* @author agapple 2013-9-6 上午11:42:04
* @since 1.0.0
*/
public class MailAlarmService extends AbstractAlarmService {

private static final String TITLE = "alarm_from_yugong";
private JavaMailSender mailSender;
private String emailUsername;
private String emailPassword;
private String emailHost;
private int stmpPort = 465;
private static final String TITLE = "alarm_from_yugong";
private JavaMailSender mailSender;
private String emailUsername;
private String emailPassword;
private String emailHost;
private int stmpPort = 465;
private boolean sslSupport = true;

@Override
public void start() {
Expand All @@ -38,7 +39,10 @@ public void start() {
pros.put("mail.smtp.port", stmpPort);
pros.put("mail.smtp.socketFactory.port", stmpPort);
pros.put("mail.smtp.socketFactory.fallback", false);
pros.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
if (sslSupport) {
pros.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
}

mailSender.setJavaMailProperties(pros);

this.mailSender = mailSender;
Expand Down Expand Up @@ -93,4 +97,8 @@ public void setStmpPort(int stmpPort) {
this.stmpPort = stmpPort;
}

public void setSslSupport(boolean sslSupport) {
this.sslSupport = sslSupport;
}

}
43 changes: 22 additions & 21 deletions src/main/java/com/taobao/yugong/controller/YuGongController.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,5 @@
package com.taobao.yugong.controller;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.sql.DataSource;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.MDC;
import org.springframework.jdbc.core.JdbcTemplate;

import com.google.common.collect.Lists;
import com.taobao.yugong.applier.AllRecordApplier;
import com.taobao.yugong.applier.CheckRecordApplier;
Expand Down Expand Up @@ -63,6 +42,27 @@
import com.taobao.yugong.positioner.RecordPositioner;
import com.taobao.yugong.translator.DataTranslator;

import java.io.File;
import java.io.FileInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Properties;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

import javax.sql.DataSource;

import org.apache.commons.configuration.Configuration;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.BooleanUtils;
import org.apache.commons.lang.StringUtils;
import org.slf4j.MDC;
import org.springframework.jdbc.core.JdbcTemplate;

/**
* 整个迁移流程调度控制
*
Expand Down Expand Up @@ -667,6 +667,7 @@ private AlarmService initAlarmService() {
alarmService.setEmailHost(config.getString("yugong.alarm.email.host"));
alarmService.setEmailUsername(config.getString("yugong.alarm.email.username"));
alarmService.setStmpPort(config.getInt("yugong.alarm.email.stmp.port", 465));
alarmService.setSslSupport(config.getBoolean("yugong.alarm.email.ssl.support", true));
return alarmService;
} else {
return new LogAlarmService();
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/yugong.properties
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@ yugong.alarm.email.host = smtp.163.com
yugong.alarm.email.username = test@163.com
yugong.alarm.email.password =
yugong.alarm.email.stmp.port = 465
yugong.alarm.receiver=test@163.com
yugong.alarm.email.ssl.support=true
yugong.alarm.receiver=test@163.com