def send_mail(content: String): Unit = {
val to: String = "xx@qq.com"
val subject: String = "mail subject"
val from: String = "xx@qq.com"
val mailhost: String = "10.199.xx.xx";
val port = 99;
val user: String = "Bigdata_notice"
val password: String = "xxxxx"
val props: Properties = new Properties()
props.setProperty("mail.smtp.host", mailhost);
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.auth", "true");
// Get a Session object
val session = Session.getInstance(props);
session.setDebug(true)
val ts = session.getTransport
ts.connect(mailhost, port, user, password);
// construct the message
val msg = new MimeMessage(session);
msg.setFrom(new InternetAddress(from));
msg.setRecipients(Message.RecipientType.TO, to);
msg.setRecipients(Message.RecipientType.CC, "xx@qq.com,xxx@bl.com")
msg.setSubject(subject);
msg.setSentDate(new Date());
msg.setContent(content, "text/html;charset=utf-8")
ts.sendMessage(msg, msg.getAllRecipients);
ts.close()
}
javax.mail发送邮件
最新推荐文章于 2024-11-14 19:53:33 发布
本文档展示了如何使用Scala编写的send_mail函数,通过SMTP协议发送带有主题、收件人和HTML内容的邮件,涉及了邮件服务器设置和Session实例化过程。
1034

被折叠的 条评论
为什么被折叠?



