java mail發送郵件demo,引入mail.jar,運行測試發送ok
[代碼][Java]代碼
01
import java.util.Date;
02
import java.util.Properties;
03
04
import javax.mail.Authenticator;
05
import javax.mail.Message;
06
import javax.mail.MessagingException;
07
import javax.mail.PasswordAuthentication;
08
import javax.mail.Session;
09
import javax.mail.Transport;
10
import javax.mail.internet.MimeMessage;
11
12
public class MailTest2 {
13
14
static Authenticator auth = new Authenticator() {
15
16
@Override
17
protected PasswordAuthentication getPasswordAuthentication() {
18
return new PasswordAuthentication("[email protected]", "fuck");
19
}
20
21
};
22
23
public static void main(String[] args) {
24
25
Properties props = new Properties();
26
props.put("mail.smtp.host", "smtp.qq.com");
27
props.put("mail.smtp.auth", "true");
28
props.put("mail.from", "[email protected]");
29
Session session = Session.getInstance(props, auth);
30
try {
31
MimeMessage msg = new MimeMessage(session);
32
msg.setFrom();
33
msg.setRecipients(Message.RecipientType.TO, "[email protected]");
34
msg.setSubject("JavaMail hello world example");
35
msg.setSentDate(new Date());
36
msg.setText("Hello, world!\n");
37
Transport.send(msg);
38
} catch (MessagingException mex) {
39
System.out.println("send failed, exception: " + mex);
40
}
41
42
}
43
}
導航菜單CSS文章來源:http://www.huiyi8.com/daohang/css/
java mail發送郵件demo 代碼
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章
Java项目面试实操 提升大厂面试成功率
wy53780
2020-04-23 14:14:04
玩转算法系列--图论精讲 面试升职必备(Java版)
wy53780
2020-04-23 14:03:23
玩转Java并发工具,精通JUC,成为并发多面手
wy53780
2020-04-23 13:56:08
线程八大核心+Java并发底层原理精讲(Java并发核心知识体系精讲)
wy53780
2020-04-23 13:55:55
Java通用型支付+电商平台双系统实战
wy53780
2020-04-23 13:54:42
【躍遷之路】【734天】程序員高效學習方法論探索系列(實驗階段491-2019.2.24)
Wall_Breaker
2019-02-24 23:25:10
Java是怎麼運行的?
勤思
2019-02-24 22:52:36
sql語法、關係建模
死瘦宅
2019-02-24 22:35:22
MySQL 事務、函數、觸發器、數據庫備份、權限管理
死瘦宅
2019-02-24 22:35:12
Python與家國天下
豌豆花下貓
2019-02-24 22:22:40
Java面試 | 002
Java貓說
2019-02-24 21:05:12
《從0到1學習Flink》—— Flink 讀取 Kafka 數據批量寫入到 MySQL
zhisheng
2019-02-24 21:04:11
Redis | 001能做什麼?
Java貓說
2019-02-24 21:03:51
java中具有繼承關係的類及其對象初始化順序
Linus脫襪子
2019-02-24 19:55:05