У меня есть вложение в моем Multipart, добавление PDF
и изображений PNG (только я покрыл PDF)
ПРИМЕЧАНИЕ: я проверяю { ссылка } Я получаю application/octet-stream
MimeBodyPart preencodedMimeBodyPart = new PreencodedMimeBodyPart("base64");
InputStream inputStream = new FileInputStream(filePDF);
preencodedMimeBodyPart.setDataHandler(new DataHandler(inputStream, "application/pdf"));
//preencodedMimeBodyPart.attachFile(filePDF);
//preencodedMimeBodyPart.setHeader("Content-Type", "application/pdf"); // NOT WORKING!!!
preencodedMimeBodyPart.setFileName(mailDTO.getNombrePDF());
preencodedMimeBodyPart.setDisposition(MimeBodyPart.ATTACHMENT);
multipart.addBodyPart(preencodedMimeBodyPart);
// INI Check the Content
MimeBodyPart lastMimeBodyPart = multipart.getBodyPart(multipart.getCount() - 1);
DataHandler dataHandler = lastMimeBodyPart.getDataHandler();
String contentType = dataHandler.getContentType();
System.out.println("contentType: " + contentType);
// END Check the Content
с использованием
preencodedMimeBodyPart.attachFile(filePDF);
работает, но я получаю: contentType: application/octet-stream
Изменение на
InputStream inputStream = new FileInputStream(filePDF);
preencodedMimeBodyPart.setDataHandler(new DataHandler(inputStream, "application/pdf"));
Изменение, contentType: application/pdf
но я получаю Исключение:
javax.mail.MessagingException: IOException while sending message;
nested exception is:
javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/pdf
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1167)
at javax.mail.Transport.send0(Transport.java:254)
at javax.mail.Transport.send(Transport.java:124)
at com.bbva.extractos.sendmail.CallableSendMail.sendOneMail(CallableSendMail.java:277)
at com.bbva.extractos.sendmail.CallableSendMail.lambda$call$0(CallableSendMail.java:93)
at java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1625)
at java.util.stream.ReferencePipeline$Head.forEach(ReferencePipeline.java:580)
at com.bbva.extractos.sendmail.CallableSendMail.call(CallableSendMail.java:74)
at com.bbva.extractos.sendmail.CallableSendMail.call(CallableSendMail.java:40)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
Caused by: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/pdf
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:896)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.PreencodedMimeBodyPart.writeTo(PreencodedMimeBodyPart.java:112)
at javax.mail.internet.MimeMultipart.writeTo(MimeMultipart.java:538)
at com.sun.mail.handlers.multipart_mixed.writeTo(multipart_mixed.java:103)
at javax.activation.ObjectDataContentHandler.writeTo(DataHandler.java:889)
at javax.activation.DataHandler.writeTo(DataHandler.java:317)
at javax.mail.internet.MimeBodyPart.writeTo(MimeBodyPart.java:1574)
at javax.mail.internet.MimeMessage.writeTo(MimeMessage.java:1840)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1119)
... 14 more
Другая альтернатива?