增加smtpPort
This commit is contained in:
@@ -15,9 +15,24 @@ import com.jeesite.common.io.PropertiesUtils;
|
|||||||
* 发送电子邮件
|
* 发送电子邮件
|
||||||
*/
|
*/
|
||||||
public class EmailUtils {
|
public class EmailUtils {
|
||||||
|
|
||||||
private final static Logger logger = LoggerFactory.getLogger(EmailUtils.class);
|
private final static Logger logger = LoggerFactory.getLogger(EmailUtils.class);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 发送邮件
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean send(String toAddress, String subject, String content) {
|
||||||
|
PropertiesUtils props = PropertiesUtils.getInstance();
|
||||||
|
String fromAddress = props.getProperty("msg.email.fromAddress");
|
||||||
|
String fromPassword = props.getProperty("msg.email.fromPassword");
|
||||||
|
String fromHostName = props.getProperty("msg.email.fromHostName");
|
||||||
|
Integer smtpPort = props.getPropertyToInteger("msg.email.smtpPort", "25");
|
||||||
|
String sslOnConnect = props.getProperty("msg.email.sslOnConnect", "false");
|
||||||
|
String sslSmtpPort = props.getProperty("msg.email.sslSmtpPort");
|
||||||
|
return send(fromAddress, fromPassword, fromHostName, smtpPort, sslOnConnect, sslSmtpPort, toAddress, subject, content);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送邮件
|
* 发送邮件
|
||||||
* @param toAddress 接收地址
|
* @param toAddress 接收地址
|
||||||
@@ -25,16 +40,12 @@ public class EmailUtils {
|
|||||||
* @param content 内容
|
* @param content 内容
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean send(String toAddress, String subject, String content) {
|
@Deprecated
|
||||||
PropertiesUtils props = PropertiesUtils.getInstance();
|
public static boolean send(String fromAddress, String fromPassword, String fromHostName,
|
||||||
String fromAddress = props.getProperty("msg.email.fromAddress");
|
String sslOnConnect, String sslSmtpPort, String toAddress, String subject, String content) {
|
||||||
String fromPassword = props.getProperty("msg.email.fromPassword");
|
return send(fromAddress, fromPassword, fromHostName, 25, sslOnConnect, sslSmtpPort, toAddress, subject, content);
|
||||||
String fromHostName = props.getProperty("msg.email.fromHostName");
|
|
||||||
String sslOnConnect = props.getProperty("msg.email.sslOnConnect", "false");
|
|
||||||
String sslSmtpPort = props.getProperty("msg.email.sslSmtpPort");
|
|
||||||
return send(fromAddress, fromPassword, fromHostName, sslOnConnect, sslSmtpPort, toAddress, subject, content);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 发送邮件
|
* 发送邮件
|
||||||
* @param toAddress 接收地址
|
* @param toAddress 接收地址
|
||||||
@@ -42,16 +53,18 @@ public class EmailUtils {
|
|||||||
* @param content 内容
|
* @param content 内容
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public static boolean send(String fromAddress, String fromPassword, String fromHostName,
|
public static boolean send(String fromAddress, String fromPassword, String fromHostName, Integer smtpPort,
|
||||||
String sslOnConnect, String sslSmtpPort, String toAddress, String subject, String content) {
|
String sslOnConnect, String sslSmtpPort, String toAddress, String subject, String content) {
|
||||||
try {
|
try {
|
||||||
HtmlEmail htmlEmail = new HtmlEmail();
|
HtmlEmail htmlEmail = new HtmlEmail();
|
||||||
// 发送地址
|
// 发送地址
|
||||||
htmlEmail.setFrom(fromAddress);
|
htmlEmail.setFrom(fromAddress);
|
||||||
// 密码校验
|
// 密码校验
|
||||||
htmlEmail.setAuthentication(fromAddress, fromPassword);
|
htmlEmail.setAuthentication(fromAddress, fromPassword);
|
||||||
// 发送服务器协议
|
// 发送服务器主机名
|
||||||
htmlEmail.setHostName(fromHostName);
|
htmlEmail.setHostName(fromHostName);
|
||||||
|
// 发送服务器端口
|
||||||
|
htmlEmail.setSmtpPort(smtpPort);
|
||||||
|
|
||||||
// SSL
|
// SSL
|
||||||
if ("true".equals(sslOnConnect)) {
|
if ("true".equals(sslOnConnect)) {
|
||||||
@@ -69,7 +82,7 @@ public class EmailUtils {
|
|||||||
|
|
||||||
// 其他信息
|
// 其他信息
|
||||||
htmlEmail.setCharset(EncodeUtils.UTF_8);
|
htmlEmail.setCharset(EncodeUtils.UTF_8);
|
||||||
|
|
||||||
// 发送
|
// 发送
|
||||||
htmlEmail.send();
|
htmlEmail.send();
|
||||||
return true;
|
return true;
|
||||||
@@ -78,10 +91,10 @@ public class EmailUtils {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
// EmailUtils.send("jeesite_demo@163.com", "jeesitedemo1234", "smtp.163.com",
|
// EmailUtils.send("jeesite_demo@163.com", "jeesitedemo1234", "smtp.163.com",
|
||||||
// "false", "465", "jeesite_demo@163.com", "测试邮件", "测试<b>邮件</b>的内容");
|
// "false", "465", "jeesite_demo@163.com", "测试邮件", "测试<b>邮件</b>的内容");
|
||||||
// }
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user