小猴子先生

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
     

MimeMessage message = null; final Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.socketFactory.fallback", "true"); props.put("mail.smtp.host", host); props.put("mail.smtp.port", port); props.put("mail.user", user); props.put("mail.password", pw); Authenticator authenticator = new Authenticator() { protected PasswordAuthentication getPasswordAuthentication(){ String userName = props.getProperty("mail.user"); String password = props.getProperty("mail.password"); return new PasswordAuthentication(userName, password); } }; Session mailSession = Session.getInstance(props, authenticator); message = new MimeMessage(mailSession); message.setFrom(new InternetAddress("邮箱地址", "邮箱名称", "UTF-8")); //1、是否需要回执--非必须 message.setHeader("Disposition-Notification-To", "<gyli1992@qq.com>"); //收件人地址 message.setRecipient(MimeMessage.RecipientType.TO, new InternetAddress("gyoyinli1992@qq.com", "user_to", "UTF-8")); //主题 message.setSubject("test02"); //内容 message.setContent("<a href='taoquan.tlong.top' style='color:#ccc'>淘券网</a>", "text/html;charset=UTF-8"); //显示发送时间 message.setSentDate(new Date()); //保存更改 message.saveChanges(); //输出eml文件 OutputStream out = new FileOutputStream("D://myemail.eml"); message.writeTo(out); out.flush(); out.close(); //发送邮件 Transport.send(message); System.out.println("邮件发送成功");

 

posted on 2018-01-17 16:10  小猴子先生  阅读(304)  评论(0编辑  收藏  举报