javax.mail
<!-- 邮件服务 --> <dependency> <groupId>javax.mail</groupId> <artifactId>mail</artifactId> <version>1.4</version> </dependency>
登录邮箱,在设置->权限中开启 POP/SMTP服务
@Test public void sendSSLEmail() { final String username = "xxxxxxxx@163.com"; Properties props = new Properties(); props.put("mail.smtp.ssl.enable", true); props.put("mail.smtp.host", "smtp.163.com"); props.put("mail.smtp.port", 465); props.put("mail.smtp.auth", "true"); Session session = Session.getDefaultInstance(props, new Authenticator() { @Override protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, "授权码"); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(username )); message.addRecipient(Message.RecipientType.TO, new InternetAddress(username )); message.setSubject("看P啊,你的代码出BUG了!!!!" + DateTool.systemTime1()); message.setText("还看,还不赶紧去改"); Transport.send(message); System.out.println("发送完毕!"); } catch (AddressException e) { e.printStackTrace(); } catch (MessagingException e) { e.printStackTrace(); } }