gpt4 book ai didi

java - Gmail 中带有附件 : html is attached as noname. html 的 Apache commons-mail HtmlEmail

转载 作者:行者123 更新时间:2023-12-01 12:52:08 32 4
gpt4 key购买 nike

我使用 apache commons-mail (v1.3.2) 发送带有 PDF 作为附件的订单确认电子邮件。电子邮件在 Outlook(网络版和桌面版)中显示没有问题,但当我发送到我的 Gmail 帐户时,邮件内容为空,并且 Html 内容附加在单独的文件“noname.html”中。

我的代码:

       // Create mail instance using commons-mail and the hybris MailUtility class.
HtmlEmail htmlEmail = (HtmlEmail) MailUtils.getPreConfiguredEmail(); // creates a mail instance with set mail
htmlEmail.setCharset("UTF-8");
htmlEmail.setHtmlMsg("this is <b>html text</b>);

// Part two is attachment
DataSource ds = new ByteArrayDataSource(mailAttachment.getData(), "application/pdf");
htmlEmail.attach(ds, "attach.pdf", "generalconditions", EmailAttachment.ATTACHMENT);
}

//send mail
htmlEmail.send();

起初,这个问题也出现在 Outlook 中,但我通过从 commons-mail v1.1 切换到 v1.3.2 解决了这个问题。不过 Gmail 仍未修复...

最佳答案

你应该使用

EmailAttachment attachment = new EmailAttachment();
attachment.setPath(pdfFile.getPath());
attachment.setDisposition(EmailAttachment.ATTACHMENT);

然后将其附加到电子邮件中,如下所示:

htmlEmail.attach(attachment);

关于java - Gmail 中带有附件 : html is attached as noname. html 的 Apache commons-mail HtmlEmail,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24144130/

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