邮件发送(示例)
程序员文章站
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);
}
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);
}