Commit 1a5613ef by yuanlin

提交包活干检修安装拆除审核驳回 finished by yuanlin

git-svn-id: svn://192.168.3.233/frms/code/car-service/trunk/car-service@26749 aeb6102e-e053-11e5-9fec-f9ebc45caf4b
1 parent ab4c9343
/*
* Copyright (c) 2018, 2028, glsx and/or its affiliates. All rights reserved.
* GLSX PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package com.glsx.ordercenter.utils;
import com.glsx.common.utils.PropertiesUtil;
import org.springframework.beans.factory.annotation.Value;
import javax.mail.*;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMessage;
import javax.mail.internet.MimeMultipart;
import java.util.Properties;
/**
* @ClassName: EmilUtils
* @Description: TODO(这里用一句话描述这个类的作用)
* @author Zheng Xiajun
* @date 2020年3月24日
*
*/
public class EmilUtils {
public final static Session EMAIL_SESSION = Session.getDefaultInstance(new Properties() {
private static final long serialVersionUID = 7930835613494309306L;
{
this.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
this.setProperty("mail.smtp.socketFactory.fallback", "false");
this.setProperty("mail.smtp.auth", "true");
}
});
private String sendMail;
// 邮箱已开通,帐号:bhgreport@didihu.com.cn初始密码为:Gsx%2019 
public final static String EMAIL_FROM_HOST = PropertiesUtil.getProperty("operator.mail.host");
// "smtphz.qiye.163.com";
public final static int EMAIL_FROM_PORT = 465;
public final static String EMAIL_FROM_ACCOUNT = PropertiesUtil.getProperty("operator.mail.username");
public final static String EMAIL_FROM_PASSWORD = PropertiesUtil.getProperty("operator.mail.pwd");
// public final static String EMAIL_TO_ACCOUNT = "zhengxj@qurongbao.com.cn";
// public final static String EMAIL_TO_ACCOUNT = "linfang@didihu.com.cn";
public final static String EMAIL_TO_ACCOUNT = PropertiesUtil.getProperty("operator.mail.sendemail");
// car.ocr.result.email.from.host=smtphz.qiye.163.com
// car.ocr.result.email.from.port=465
// car.ocr.result.email.from.account=bhgreport@didihu.com.cn
// car.ocr.result.email.from.password=Gsx%2019
// car.ocr.result.email.to=zhengxj@qurongbao.com.cn
public final static String SPLIT_CHAR = ";";
public static void sendEmail(String address, String title, String content) throws Exception {
Transport transport = null;
if (null != address && address.trim().length() > 0) {
MimeMessage message = new MimeMessage(EMAIL_SESSION);
message.setFrom(new InternetAddress(EMAIL_FROM_ACCOUNT));
for (String addr : address.trim().split(SPLIT_CHAR)) {
if (null != addr && addr.trim().length() > 0)
message.addRecipient(Message.RecipientType.TO, new InternetAddress(addr.trim()));
}
message.setSubject(title);
Multipart part = new MimeMultipart();
BodyPart contentPart = new MimeBodyPart();
contentPart.setContent(content, "text/html; charset=UTF-8");
part.addBodyPart(contentPart);
message.setContent(part);
transport = EMAIL_SESSION.getTransport("smtp");
transport.connect(EMAIL_FROM_HOST, EMAIL_FROM_PORT, EMAIL_FROM_ACCOUNT, EMAIL_FROM_PASSWORD);
message.saveChanges();
try {
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
} finally {
close(transport);
}
}
}
public static void close(Transport s) { // transport, store
if (null != s) {
try {
s.close();
} catch (Exception e) {
e.printStackTrace();
}
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!