邮件发送
private static final String USER = ""; private static final String PASSWORD = "";@Testpublic void m5() {StringBuilder content = new StringBuilder("" + 111 + "" +",您好:
您有新的岗位人员需要验收,具体情况如下:
员工:" +1 + "
线体:" +1+ "
岗位:" + 1 );content.append("");content.append("| 姓名 | 线体 | 岗位 | 是否首次操作该岗位 | 培训方式 | 打卡日期 | 验收状态 |
");for (int i = 0; i < 1; i++) {content.append("");content.append("| 1 | ");content.append("1 | ");content.append("1 | ");content.append("1 | ");content.append("1 | ");content.append("1 | ");content.append("1 | ");content.append("
");}content.append("
");content.append("");sendMail("发件人邮箱", content.toString(), "测试用");System.out.println("发送成功");}public static boolean sendMail (String to, String text, String title){try {final Properties props = new Properties();props.setProperty("mail.transport.protocol", "SMTP");props.setProperty("mail.smtp.auth", "true");props.setProperty("mail.smtp.host", "IP地址/域名");props.put("mail.user", USER);props.put("mail.password", PASSWORD);Authenticator authenticator = new Authenticator() {@Overrideprotected 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);MimeMessage message = new MimeMessage(mailSession);String username = props.getProperty("mail.user");InternetAddress form = new InternetAddress(username);message.setFrom(form);InternetAddress toAddress = new InternetAddress(to);message.setRecipient(Message.RecipientType.TO, toAddress);message.setSubject(title);message.setContent(text, "text/html;charset=UTF-8");Transport.send(message);return true;} catch (Exception e) {e.printStackTrace();}return false;}
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!