The problem I’m experiencing is when I add the message Body part of the e-mail to the message object before I add the attachments the body of the e-mail doesn’t show up, but when I add the message body part after all the attachments it shows up fine.
This is weird, but I have an e-mail I’m trying to send using JavaMail. It has all the regular stuff you need for an e-mail (addresses, etc). The “email” object you’ll see below is a Javabean that holds mimeBodyParts for attachments as well as a mimeBodyPart for the message body, subject, etc…
Here’s the code that does not work (as described above)
Multipart multipart = new MimeMultipart("alternative");
message.setSubject(email.getSubject());
multipart.addBodyPart(email.getContentBodyPart()); //This is the only line that moves
for (MimeBodyPart mimeBodyPart : email.getBodyParts()) {
multipart.addBodyPart(mimeBodyPart);
}
message.setContent(multipart);
Here’s the code that does work:
Multipart multipart = new MimeMultipart("alternative");
message.setSubject(email.getSubject());
for (MimeBodyPart mimeBodyPart : email.getBodyParts()) {
multipart.addBodyPart(mimeBodyPart);
}
multipart.addBodyPart(email.getContentBodyPart()); //This is the only line that moved
message.setContent(multipart);
If you need more info about the email javabean I’ll give it to you (or you can find the entire object code here), but I’m guessing I’m just missing something simple. Thanks in advance.
If you’re creating a message with attachments, why are you using a multipart/alternative? You should be using the (default) multipart/mixed.
Did you cut and paste that code without understanding it? 🙂