问题
As of know my email application was supporting only plain text with attachments. I was handling it in a simple way if attachment list is null, simply send the mime message and if attchment list is not null, i was creating body part for each attachment and one for body. Adding them in multipart which is set in to mime message.
But now need to support the html part and inline images(where images will be sent as attachment and html body will be referreing).I know the basics of mime i.e how to create the body parts for each mime type. But really i am not getting how to create the body parts at run timw when i do not what body and attachment list will contain. For example body can contain only plain text or html body or html body with attachment or html body with inline image with attachment or plain body with attchment.
Frankly i am not getting how to process the emailbody and attachment list for above mentioned permuations and combinations.(for example some time i need to create top message as multipart/mixed containg body parts as mulipart/alternative and another body part plain, bla bla....). Is there standard code handling these all scenarios based on body content and attachment list. Please point me in right direction?
here is the old method signature which was supporting only plain text with attachments
public void sendMimeEmail(List toMailAddresses,
String fromMailAddress, String body, List<AttachmentData> attachments) {}
回答1:
I don't think there's any magic here. You just need enough "if" statements to cover the cases.
来源:https://stackoverflow.com/questions/13177068/sending-mime-message-containing-any-of-these-attachment-htmlbody-inline-image-o