Part is attachment when disposition is null and Content-ID is unique. by YYChildren · Pull Request #34 · bbottema/simple-java-mail

Expand Up @@ -472,10 +472,12 @@ private static BodyPart getBodyPartFromDatasource(final AttachmentResource resou final BodyPart attachmentPart = new MimeBodyPart(); final DataSource ds = resource.getDataSource(); // setting headers isn't working nicely using the javax mail API, so let's do that manually String contentId= resource.getName(); String fileName = ds.getName() != null ? ds.getName() : contentId; attachmentPart.setDataHandler(new DataHandler(resource.getDataSource())); attachmentPart.setFileName(resource.getName()); attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + ds.getName() + "; name=" + ds.getName()); attachmentPart.setHeader("Content-ID", String.format("<%s>", ds.getName())); attachmentPart.setFileName(fileName); attachmentPart.setHeader("Content-Type", ds.getContentType() + "; filename=" + fileName + "; name=" + fileName); attachmentPart.setHeader("Content-ID", String.format("<%s>", contentId)); attachmentPart.setDisposition(dispositionType + "; size=0"); return attachmentPart; } Expand Down