1. /**
2. * JavaMail SMTP服务器发送邮件程序示例
3. * 扮演SMTP服务器角色与邮件客户端软件最大的区别就是:
4. * SMTP服务器需要解析不同接收人邮件地址主机名对应的SMTP服务器主机名
5. * ,同时不需要验证
6. * 注意:由于条件的限制,此程序是运行不成功的,原因见下面的注释说明
7. */
8. package
9. import
10. import
11. import
12. import
13. import
14. import
15. import
16. import
17. import
18. import
19. import
20. import
21. import
22. import
23. /**
24. * @author Bill Tu
25. * @since May 27, 2011(12:21:41 PM)
26. *
27. */
28. public class
29. public static String getSMTPHost(String domain,String dnsServer) throws
30. new
31. null;
32. if(null
33. "dns://"+dnsServer+"/"+domain,new String[]{"MX"});
34. else{
35. "dns:/"+domain,new String[]{"MX"});
36. }
37.
38. "MX").get();
39. " ")+1);
40. return
41. }
42.
43. private static Message getMessage(Session session) throws
44. "iwtxokhtd@163.com";
45. "hello";
46. "this is content";
47.
48. new
49. new
50. msg.setSubject(subject);
51. msg.setText(content);
52. new
53.
54. return
55.
56. }
57.
58. private static
59. new
60. //设置ehlo命令中的主机名,若检测到主机名与其IP地址一致,则认为这时的发送方是SMTP服务器,就不需要验证;否则就是邮件客户端软件,则需要验证。
61. "mail.smtp.localhost", "mail.digu.com");
62. "mail.smtp.auth", "false");
63. "mail.smtp.port", "25");
64. Session session=Session.getDefaultInstance(props);
65. true);
66. return
67. }
68.
69. @SuppressWarnings("static-access")
70. private static void
71. throws
72. message.setRecipients(RecipientType.TO, InternetAddress.parse(to));
73. message.saveChanges();
74.
75. "smtp");
76.
77. "@")+1);
78. null);
79.
80. null, null);
81. transport.send(message, message.getRecipients(Message.RecipientType.TO));
82.
83. transport.close();
84. }
85.
86. public static void
87. throws
88. new String[]{"277515444@qq.com","277515445@qq.com"};
89. Session session=getSession();
90. Message msg=getMessage(session);
91. for(String email:to){
92. sendEmail(msg,session,email);
93. }
94. }
95. }
电子邮件系统 4----JavaMail SMTP服务器发送邮件程序示例 .
原创
©著作权归作者所有:来自51CTO博客作者iwtdigu的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:远程桌面之服务器端的设置
下一篇:远程桌面之网络环境的配置
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
使用Docker部署mailcow开源邮件系统详细过程
本文主要介绍基于Docker的mailcow开源邮件系统的部署过程
Docker mailcow 电子邮件 -
JavaMail使用SMTP协议发送电子邮件(详解)JavaMail