最代码官方
2012-07-27 15:47:27
原证
java实现发邮件的代码
通过java发送邮件的代码
如果是QQ或163的smtp服务,那port是25,而gmail的port是587
String host = "smtp.163.com"; int port = 25; String username = "zuidaima"; String password = "xxxxxx; Properties javaMailProperties = new Properties(); javaMailProperties.put("mail.smtp.auth", "true"); javaMailProperties.put("mail.smtp.starttls.enable", "true"); JavaMailSenderImpl mailSender = new JavaMailSenderImpl(); mailSender.setHost(host); mailSender.setPort(port); mailSender.setUsername(username); mailSender.setPassword(password); mailSender.setJavaMailProperties(javaMailProperties); String email = "zuidaima@gmail.com"; String nickname = "张三"; MimeMessage message = mailSender.createMimeMessage(); MimeMessageHelper help = new MimeMessageHelper(message, true, "UTF-8"); help.setFrom("zuidaima@163.com"); help.setTo(new String[]{"3314687058@qq.com", email}); help.setSubject("测试"); String content = "你好" + nickname; help.setText(content, true); try { mailSender.send(message); } catch (Throwable e) { e.printStackTrace(); }
运行截图
相关lib包百度网盘下载
https://pan.baidu.com/s/1hr7JWGG
项目截图
猜你喜欢
请下载代码后再发表评论


喵小兵 LV10
2021年3月13日
zhkai163 LV5
2020年8月16日
周大福 LV12
2020年2月27日
xjf0309xjf LV8
2020年1月9日
644106 LV8
2019年7月11日
刘芳雄 LV5
2019年6月27日
fzj0921 LV1
2019年3月11日
wzd_yz LV13
2019年1月31日
qq389344480 LV8
2018年9月29日
administratoa LV6
2018年8月28日

dapeng0011 LV15
2024年7月17日
2036495585 LV9
2023年9月25日
annazhang LV29
2023年4月8日
15997352948 LV2
2023年3月22日
Tuxxxxx LV3
2023年1月3日
heqian LV17
2022年10月17日
豆子小兔子 LV9
2022年10月2日
沐兮20010401 LV7
2022年9月14日
crosa_Don LV18
2022年7月19日
unknown_turtleshell LV3
2022年5月6日