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