欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

邮件发送(示例)

程序员文章站 2022-05-24 18:52:45
...
public static void sendMail() throws MessagingException {
Properties props = System.getProperties();
props.put("mail.smtp.host", "internet1.lotus.com");
Session session = Session.getInstance(props);

MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("luoyafei@cn.ibm.com"));
msg.addRecipient(RecipientType.TO, new InternetAddress(
"luoyafei@cn.ibm.com"));
msg.addRecipient(RecipientType.CC, new InternetAddress(
"luoyafei@cn.ibm.com"));
msg.addRecipient(RecipientType.BCC, new InternetAddress(
"luoyafei@cn.ibm.com"));
msg.setSubject("only test", "UTF-8");

Multipart mp = new MimeMultipart();
BodyPart part = new MimeBodyPart();
// html 格式
// part.setHeader("Content-Type", "text/html; charset=utf-8");
part.setText("test");
mp.addBodyPart(part);
msg.setContent(mp);

Transport.send(msg);
}
相关标签: mail