/**
* 发送普通邮件
*
* @param toMailAddr
* 收信人地址
* @param ccMailAddr
* 抄送人地址
* @param subject
* email主题
* @param message
* 发送email信息
*/
public static void sendCommonMail(String toMailAddr,String ccMailAddr, String subject,
String message) {
HtmlEmail hemail = new HtmlEmail();
try {
String [] tos = null;
if(toMailAddr.contains(",")){
String[] split = toMailAddr.split(",");
tos = new String[split.length];
for (int i = 0; i < split.length; i++) {
tos[i] = split[i];
}
}else{
tos = new String[1];
tos[0]=toMailAddr;
hemail.addTo(tos);
hemail.addCc(ccMailAddr);
hemail.setFrom(from, fromName);
hemail.setAuthentication(username, password);
hemail.setSubject(subject);
hemail.setMsg(message);
hemail.send();
log.info("email send true!");
} catch (Exception e) {
e.printStackTrace();
log.error("email send error!");
}
}
* 发送普通邮件
*
* @param toMailAddr
* 收信人地址
* @param ccMailAddr
* 抄送人地址
* @param subject
* email主题
* @param message
* 发送email信息
*/
public static void sendCommonMail(String toMailAddr,String ccMailAddr, String subject,
String message) {
HtmlEmail hemail = new HtmlEmail();
try {
String [] tos = null;
if(toMailAddr.contains(",")){
String[] split = toMailAddr.split(",");
tos = new String[split.length];
for (int i = 0; i < split.length; i++) {
tos[i] = split[i];
}
}else{
tos = new String[1];
tos[0]=toMailAddr;
}
//需要开区ssl协议
hemail.setSSL(true);hemail.setHostName("smtp.163.com");
//端口号
hemail.setSmtpPort("465");
hemail.setCharset(charSet);hemail.addTo(tos);
hemail.addCc(ccMailAddr);
hemail.setFrom(from, fromName);
hemail.setAuthentication(username, password);
hemail.setSubject(subject);
hemail.setMsg(message);
hemail.send();
log.info("email send true!");
} catch (Exception e) {
e.printStackTrace();
log.error("email send error!");
}
}