gpt4 book ai didi

java - java : email with pdf attached file : no object DCH for MIME type application/pdf

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:17:02 24 4
gpt4 key购买 nike

我想用 javax 邮件在电子邮件中发送 pdf 文件。
下面,baos 是一个 ByteArrayOutputStream。

byte []  data=   baos.toByteArray();
OutputStream output = new FileOutputStream(fileName);
output.write(data);
output.close();
DataSource source = new FileDataSource(fileName);
attachBodyPart.setDataHandler(new DataHandler(source, "application/pdf"));
attachBodyPart.setFileName(fileName);
multipart.addBodyPart(attachBodyPart);
message.setContent(multipart, "text/html");
Transport transport = session.getTransport("smtp");
transport.connect(host, from, pass);
transport.sendMessage(message, message.getAllRecipients());
transport.close();

当我尝试发送电子邮件时出现此异常:

javax.mail.MessagingException: IOException while sending message;
nested exception is: javax.activation.UnsupportedDataTypeException: no object DCH for MIME type application/pdf

我不知道这里出了什么问题。
如果有人这样做...

提前致谢。

最佳答案

试试这个。

MimeBodyPart attachment = new MimeBodyPart();
DataSource dataSrc = new ByteArrayDataSource(baos.toByteArray(), "application/pdf");
attachment.setDataHandler(new DataHandler(dataSrc));
attachment.setFileName("myPdfDocument.pdf");
multipart.addBodyPart(attachment);

关于java - java : email with pdf attached file : no object DCH for MIME type application/pdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33933145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com