在Google官方网站上,这是一种在发送之前创建电子邮件的方法。
public static MimeMessage createEmail(String to,
String from,
String subject,
String bodyText)
throws MessagingException {
Properties props = new Properties();
Session session = Session.getDefaultInstance(props, null);
MimeMessage email = new MimeMessage(session);
email.setFrom(new InternetAddress(from));
email.addRecipient(javax.mail.Message.RecipientType.TO,
new InternetAddress(to));
email.setSubject(subject);
email.setText(bodyText);
return email;
}
我找不到可以为CC电子邮件地址和发件人姓名设置的API。 我在互联网上搜索,也找不到答案。请帮帮忙。
答案 0 :(得分:1)
使用setter方法
设置收件人 message.addRecipient(RecipientType.BCC, new InternetAddress(to));
message.addRecipient(RecipientType.CC, new InternetAddress(to));
答案 1 :(得分:1)
您可以尝试以下方式
message.addRecipient(RecipientType.BCC, new InternetAddress(
"your@email.com"));
message.addRecipient(RecipientType.CC, new InternetAddress(
"yourOther@email.com"));
归功于him