/** * Attaches a file as a body part to the multipart message * * @param attachment * @throws MessagingException */ private MimeBodyPart createAttachmentPart(Attachment attachment) throws MessagingException { DataSource source = attachment.getDataSource(); MimeBodyPart attachPart = new MimeBodyPart(); attachPart.setDataHandler(new DataHandler(source)); attachPart.setFileName(attachment.getFilename()); if (attachment.getContentTypeHeader() != null) { attachPart.setHeader("Content-Type", attachment.getContentTypeHeader()); } if (attachment.getContentDispositionHeader() != null) { attachPart.setHeader("Content-Disposition", attachment.getContentDispositionHeader()); } return attachPart; }