I want to make an email and extract the content in a .eml file. I don't understand why the following code doesn't works (at least, not like i want) :
public String getEML() {
final Properties properties = new Properties();
properties.setProperty("mail.transport.protocol", "smtp");
final Session session = Session.getInstance(properties);
final MimeMessage message = new MimeMessage(session);
final MimeMultipart mimeMultipart = new MimeMultipart("related");
try {
mimeMultipart.addBodyPart(getHtml());
for(MimeBodyPart bodyPart : getImgs()) {
mimeMultipart.addBodyPart(bodyPart);
}
//I don't want to send my mail in my code. I would like to extract an eml before.
message.addHeader("X-Unsent", "1");
message.setContent(mimeMultipart);
message.setSubject("the subject");
message.setRecipient(RecipientType.TO, new InternetAddress("yyy@yyy.com"));
message.setRecipient(RecipientType.BCC, new InternetAddress("xxx@xxx.com"));
} catch (final MessagingException e) {
e.printStackTrace();
}
// This function return the content of the mail in a String
return messageMimeToString(message);
}
The .eml generated correspond to that i want. But, when I import this file in Outlook 2016, the BCC (Cci) is not set. However, the first line of the .eml is :
Bcc: xxx@xxx.com
Could someone explain this behaviour to me ?
EDIT: Just for more precision, when I replace RecipientType.BCC by RecipientType.TO or RecipientType.CC, it works.