With JavaMail, I am building messages with the following format
+------------------------------------------------+
| multipart/related |
| +---------------------------+ +-------------+ |
| |multipart/alternative | | attachments | |
| | +-----------+ +---------+ | | | |
| | |text/plain | |text/html| | | | |
| | +-----------+ +---------+ | | | |
| +---------------------------+ +-------------+ |
+------------------------------------------------+
ASCII art attributed to the OP of this question: http://www.coderanch.com/t/503380/java/java/Java-Mail-text-html-attachment
I felt that this would be the correct format, since the attachments (image/gif, application/pdf, etc.) are important in understanding the message as a whole. However, I've been doing some researching and have found that oftentimes multipart/mixed
is used.
Should I replace the multipart/related
section with multipart/mixed
? If so, why?
An example message in this format would be as follows:
Content-Type: multipart/related;
boundary="----=_Part_6818257_562311419.1408632937947"
------=_Part_6818257_562311419.1408632937947
Content-Type: multipart/alternative;
boundary="----=_Part_6818256_1953685207.1408632937947"
------=_Part_6818256_1953685207.1408632937947
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 7bit
This is my message!
------=_Part_6818256_1953685207.1408632937947
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 7bit
<html><strong>This is my message!</strong></html>
------=_Part_6818256_1953685207.1408632937947--
------=_Part_6818257_562311419.1408632937947
Content-Type: application/pdf;name="document.pdf"
Content-Transfer-Encoding: base64
Content-ID: <attachment0>
X-Attachment-Id: attachment0
< insert lots of base64 encoding here >
------=_Part_6818257_562311419.1408632937947--