Reputation: 1037
From Google official website, this is a method to create a email before sending.
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;
}
I can't find the API which I can set for CC email address and sender name. I searched on internet and also can't find the answer. Please have a help on this.
Upvotes: 2
Views: 671
Reputation: 23394
you can try following way
message.addRecipient(RecipientType.BCC, new InternetAddress(
"[email protected]"));
message.addRecipient(RecipientType.CC, new InternetAddress(
"[email protected]"));
credit to him
Upvotes: 1
Reputation: 1058
Set recipients with the setter method
message.addRecipient(RecipientType.BCC, new InternetAddress(to));
message.addRecipient(RecipientType.CC, new InternetAddress(to));
Upvotes: 2