Skip to content

Commit

Permalink
Merge pull request #17 from spidersq/master
Browse files Browse the repository at this point in the history
报警邮件是否使用ssl方式可配置
  • Loading branch information
agapple authored Jun 29, 2016
2 parents ce5ac2c + 6816b20 commit 615ec43
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
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 = [email protected]
yugong.alarm.email.password =
yugong.alarm.email.stmp.port = 465
yugong.alarm.receiver=[email protected]
yugong.alarm.email.ssl.support=true
yugong.alarm.receiver=[email protected]

0 comments on commit 615ec43

Please sign in to comment.