Java???????Java Mail??Apache Mail
???????????? ???????[ 2014/6/10 11:36:32 ] ????????Java ???
?????????????
?????????????????????????????????£????????????????????糭????
????1??????????????????????????xxx@xx.com
????2??????????????????????????????????????loadfate 779554589@qq.com
????3??????????????????????
????4??????????????
????5??????????????
????6?????????????????????????
???????????Java?????????ò???
???????????????е?????????????????????????????????????????
????1??????smtp???????????????????????в???????????磺smtp.qq.com????????smtp????????
????2??????????÷??????????????????÷???????
????3??????????????????????????????????????緢?????????????????
????4??????????????????????????????????
????5???????????????????????????????????
????????Java Mail??Apache Mail
????Apache Mail???Java Mail?????????????????????????θи??á?
???????Java Mail???????????jar????mail.jar??
???????Apache Mail????????????????jar????mail.jar??commons-email-1.3.1.jar??
??????????Java Mail???????
1 public static void main(String[] args) throws Exception {
2 final String user = "779554589";
3 final String password = "";
4
5 String fromAddress = "779554589@qq.com";
6 String toAddress = "loadfate@163.com";
7 String subject = "???????????";
8 String content = "??????????????<b>????</b>";
9
10 //???ò???
11 Properties props = new Properties();
12 props.setProperty("mail.smtp.auth"?? "true");
13 props.setProperty("mail.transport.protocol"?? "smtp");
14 props.setProperty("mail.host"?? "smtp.qq.com");
15 // ??????????transport?????????
16 {
17 //????????????
18 Session session = Session.getInstance(props);
19 //?????????
20 session.setDebug(true);
21 //?????????????????????
22 Message message = new MimeMessage(session);
23 message.setFrom(new InternetAddress(fromAddress));
24 message.setSubject(subject);
25 message.setText(content);
26 //????????
27 Transport transport = session.getTransport();
28 //????smtp??????
29 transport.connect(user?? password);
30 //????
31 transport.sendMessage(message?? new InternetAddress[] { new InternetAddress(toAddress) });
32 transport.close();
33 }
34
35
36 // ???????????Transport??????????????
37 {
38 //????Session????????????
39 Session session = Session.getInstance(props?? new Authenticator() {
40 @Override
41 protected PasswordAuthentication getPasswordAuthentication() {
42 return new PasswordAuthentication(user?? password);
43 }
44 });
45 session.setDebug(true);
46 //?????????????????????
47 Message message = new MimeMessage(session);
48 message.setSubject(subject);
49 message.setFrom(new InternetAddress(fromAddress));
50 message.setRecipient(RecipientType.TO?? new InternetAddress(toAddress));
51 message.setContent(content?? "text/html;charset=utf-8");
52
53 //???????message???????????Session????
54 Transport.send(message);
55 }
56 }
|
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11