日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > HTML >内容正文

HTML

腾讯邮件服务器发送慢,通过腾讯邮件服务器发送HTML邮件

發(fā)布時間:2024/7/5 HTML 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 腾讯邮件服务器发送慢,通过腾讯邮件服务器发送HTML邮件 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

郵件發(fā)送工具:

private static String host = "smtp.exmail.qq.com";// 服務器地址

private static String port = "465";// 端口

private static String protocol = "smtp";// 協(xié)議

public static Session initProperties(String account, String password) {

Properties properties = new Properties();

properties.setProperty("mail.transport.protocol", protocol);

properties.setProperty("mail.smtp.host", host);

properties.setProperty("mail.smtp.port", port);

// 使用smtp身份驗證

properties.put("mail.smtp.auth", "true");

// 開啟安全協(xié)議

MailSSLSocketFactory mailSSLSocketFactory = null;

try {

mailSSLSocketFactory = new MailSSLSocketFactory();

mailSSLSocketFactory.setTrustAllHosts(true);

} catch (GeneralSecurityException e) {

e.printStackTrace();

}

properties.put("mail.smtp.enable", "true");

properties.put("mail.smtp.ssl.socketFactory", mailSSLSocketFactory);

properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

properties.put("mail.smtp.socketFactory.fallback", "false");

properties.put("mail.smtp.socketFactory.port", port);

Session session = Session.getDefaultInstance(properties, new Authenticator() {

@Override

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(account, password);

}

});

session.setDebug(true);

return session;

}

/**

* @Description: 發(fā)送郵件

* @Title: send

* @date 2019-10-08 17:12

* @param @param sender發(fā)件人別名

* @param @param subject郵件主題

* @param @param content接收者列表,多個接收者之間用","隔開

* @param @param receiverList

* @param @param fileSrc 附件地址

* @return void 返回類型

* @throws @return void

* @param sender

* @param subject

* @param content

* @param receiverList

* @param fileSrc

*/

public void send(String sender, String subject, String content, String receiverList, String fileSrc, String account,

String password) {

try {

Session session = initProperties(account, password);

MimeMessage mimeMessage = new MimeMessage(session);

mimeMessage.setFrom(new InternetAddress(account, sender));// 發(fā)件人,可以設置發(fā)件人的別名

// 收件人,多人接收

InternetAddress[] internetAddressTo = new InternetAddress().parse(receiverList);

mimeMessage.setRecipients(Message.RecipientType.TO, internetAddressTo);

// 主題

mimeMessage.setSubject(subject);

// 時間

mimeMessage.setSentDate(new Date());

// 容器類 附件

MimeMultipart mimeMultipart = new MimeMultipart();

// 附件

MimeBodyPart bodyPart = new MimeBodyPart();

// 設置內(nèi)容

bodyPart.setContent(content, "text/html; charset=UTF-8");

mimeMultipart.addBodyPart(bodyPart);

// 添加圖片&附件

bodyPart = new MimeBodyPart();

bodyPart.attachFile(fileSrc);

mimeMultipart.addBodyPart(bodyPart);

mimeMessage.setContent(mimeMultipart);

mimeMessage.saveChanges();

Transport.send(mimeMessage);

} catch (MessagingException e) {

e.printStackTrace();

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}

}

測試類:

public static void main(String[] args) throws Exception {

String account = "[email?protected]";// 登錄賬戶

String password = "xxxxxxxxxxxxxxx";// 登錄密碼

SendEmailUtil tenMailUtil = new SendEmailUtil();

tenMailUtil.send("發(fā)件人別名", "郵件主題", "

HhhhHHHHHHH

",

"[email?protected],[email?protected]", "C:/Users/Administrator/Desktop/index.html", account,

password);

}

原文:https://www.cnblogs.com/yhm9/p/11642775.html

總結

以上是生活随笔為你收集整理的腾讯邮件服务器发送慢,通过腾讯邮件服务器发送HTML邮件的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。