| | |
| | | // 指定发送邮件的主机为 |
| | | String host = "smtp.163.com"; |
| | | Properties properties = new Properties(); |
| | | properties.put("mail.smtp.host", "smtp.163.com"); |
| | | properties.put("mail.smtp.host", host); |
| | | properties.put("mail.smtp.socketFactory.port", "465"); |
| | | properties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory"); |
| | | properties.put("mail.smtp.auth", "true"); |
| | |
| | | public javax.mail.PasswordAuthentication getPasswordAuthentication() |
| | | { |
| | | //发件人邮件用户名、授权码,换成自己的发件箱及授权码 |
| | | return new PasswordAuthentication("13281306557@163.com", "NUSdxDQqadYvVek2"); |
| | | return new PasswordAuthentication(from, "NUSdxDQqadYvVek2"); |
| | | } |
| | | }); |
| | | |
| | |
| | | // Set From,设置发件人 |
| | | InternetAddress fromMail = new InternetAddress(from); |
| | | //设置发件人名称,TODO 换成自己的发件箱 |
| | | fromMail.setPersonal(MimeUtility.encodeText("明星新能源科技有限公司<13281306557@163.com>")); |
| | | fromMail.setPersonal(MimeUtility.encodeText("明星新能源科技有限公司<" + from + ">")); |
| | | message.setFrom(fromMail); |
| | | // Set To: 设置收件人 |
| | | InternetAddress toMail = new InternetAddress(to); |