~/ 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/c45e7d9b-60d3-4222-a0d0-054076a3617b/flashcard utf-8 LF