com.centit.support.network.SendMailExecutor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of centit-utils Show documentation
Show all versions of centit-utils Show documentation
java 常用工具类,作为 apache-commons的补充
package com.centit.support.network;
import java.io.File;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.MultiPartEmail;
@SuppressWarnings("unused")
public abstract class SendMailExecutor {
protected static final Logger logger = LoggerFactory.getLogger(SendMailExecutor.class);
public static String mailHost = "";
public static String mailUser = "";
public static String mailPassword = "";
public static int smtpPort = 25;
public static void setMailServer(String mailHost,String mailUser,String mailPassword) {
SendMailExecutor.mailHost = mailHost;
SendMailExecutor.mailUser = mailUser;
SendMailExecutor.mailPassword = mailPassword;
}
public static void setMailServer(String mailHost,String mailUser,String mailPassword,int smtpPort) {
SendMailExecutor.mailHost = mailHost;
SendMailExecutor.mailUser = mailUser;
SendMailExecutor.mailPassword = mailPassword;
SendMailExecutor.smtpPort = smtpPort;
}
public static boolean sendEmail(String [] mailTo, String mailFrom,
String msgSubject, String msgContent) {
MultiPartEmail multMail = new MultiPartEmail();
// SMTP
multMail.setHostName(mailHost);
multMail.setSmtpPort(smtpPort);
// 需要提供公用的邮件用户名和密码
multMail.setAuthentication(
mailUser,
mailPassword);
try {
//multMail.setFrom(CodeRepositoryUtil.getValue("SysMail", "admin_email"));
multMail.setFrom(mailFrom);
multMail.addTo(mailTo);
multMail.setSubject(msgSubject);
msgContent = msgContent.trim();
if(msgContent.endsWith("