~/ learn/ comp-348/ cards/ Attachments: MimeMultipart and MimeBodyPart
1 of 5

A two-part multipart/mixed body: text first, file second

A two-part multipart/mixed body: text first, file second

Answer

MimeBodyPart textPart = new MimeBodyPart(); textPart.setText(body); MimeBodyPart filePart = new MimeBodyPart(); filePart.attachFile(new File(path)); MimeMultipart mixed = new MimeMultipart(); mixed.addBodyPart(textPart); mixed.addBodyPart(filePart); msg.setContent(mixed);

new MimeMultipart() defaults to the mixed subtype. attachFile builds the FileDataSource, sets the attachment disposition and the filename; setContent then swaps the whole subtree in as the message body.

Jakarta Mail API §MimeMultipart, §MimeBodyPart

space flip · ← → navigate · esc to exit
NORMAL ~/memra/library/93807e49-2b08-4113-9beb-1f0b64a32d67/flashcard utf-8 LF