HtmlEmail 未正确呈现 HTML (apache commons)
希望有人能找到我丢失的东西。我正在尝试在 java 应用程序中发送简单的 HTML 电子邮件。我使用 commons-mail 1.1 (通过 Maven)作为我的邮件库。
我使用的代码是:
HtmlEmail email = new HtmlEmail();
email.setDebug(true);
email.setHostName("my.emailhost.com");
email.addTo("[email protected]");
email.setFrom("[email protected]");
email.setSubject("Test Subject");
email.setHtmlMsg("<b>This is a bolded message</b>");
email.setTextMsg("This is a text message");
email.send();
我正在收到电子邮件,但它的格式是这样的。还应该注意的是,没有主题,但我显然在代码中指定了一个。
------=_Part_0_122395252.1304699110505
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This is a text message
------=_Part_0_122395252.1304699110505
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<b>This is a bolded message</b>
------=_Part_0_122395252.1304699110505--
我不确定我在这里做错了什么。我改用 gmail 发送 - 它确实发送了,只是格式完全相同。当我查看原始消息时,我看到
Delivered-To: [email protected]
Received: by 10.90.73.11 with SMTP id v11cs143993aga;
Fri, 6 May 2011 09:25:11 -0700 (PDT)
Received: by 10.236.187.97 with SMTP id x61mr4380232yhm.476.1304699111088;
Fri, 06 May 2011 09:25:11 -0700 (PDT)
Return-Path: <[email protected]>
Received: from xxxxxxx.xxxxxxx.com (xxxxxxx.xxxxxxx.com [x.x.x.x])
by mx.google.com with ESMTP id 68si9400486yhl.82.2011.05.06.09.25.10;
Fri, 06 May 2011 09:25:10 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates x.x.x.x as permitted sender) client-ip=x.x.x.x;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of [email protected] designates x.x.x.x as permitted sender) [email protected]
Received: from xxxxxxx-mac-pro.local ([x.x.x.x])
by xxxxxxx.xxxxxxx.com (Lotus Domino Release 8.5.1FP3)
with ESMTP id 2011050612251028-17357 ;
Fri, 6 May 2011 12:25:10 -0400
From: [email protected]
Date: Fri, 6 May 2011 12:25:10 -0400
Message-ID: <[email protected]>
任何想法将不胜感激。
干杯
Hoping that someone can find something I am missing. I am trying to send a simple HTML email within a java application. I am using commons-mail 1.1 (via maven) as my mail lib.
The code I'm using is:
HtmlEmail email = new HtmlEmail();
email.setDebug(true);
email.setHostName("my.emailhost.com");
email.addTo("[email protected]");
email.setFrom("[email protected]");
email.setSubject("Test Subject");
email.setHtmlMsg("<b>This is a bolded message</b>");
email.setTextMsg("This is a text message");
email.send();
I am receiving the email, but it is formatted thusly. It should also be noted that there is no subject, but I obviously specified one in my code.
------=_Part_0_122395252.1304699110505
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
This is a text message
------=_Part_0_122395252.1304699110505
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit
<b>This is a bolded message</b>
------=_Part_0_122395252.1304699110505--
I'm not sure what I'm doing wrong here. I switched to sending via gmail - and it did send, it just formatted it exactly the same. When i view the raw message I see
Delivered-To: [email protected]
Received: by 10.90.73.11 with SMTP id v11cs143993aga;
Fri, 6 May 2011 09:25:11 -0700 (PDT)
Received: by 10.236.187.97 with SMTP id x61mr4380232yhm.476.1304699111088;
Fri, 06 May 2011 09:25:11 -0700 (PDT)
Return-Path: <[email protected]>
Received: from xxxxxxx.xxxxxxx.com (xxxxxxx.xxxxxxx.com [x.x.x.x])
by mx.google.com with ESMTP id 68si9400486yhl.82.2011.05.06.09.25.10;
Fri, 06 May 2011 09:25:10 -0700 (PDT)
Received-SPF: pass (google.com: domain of [email protected] designates x.x.x.x as permitted sender) client-ip=x.x.x.x;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of [email protected] designates x.x.x.x as permitted sender) [email protected]
Received: from xxxxxxx-mac-pro.local ([x.x.x.x])
by xxxxxxx.xxxxxxx.com (Lotus Domino Release 8.5.1FP3)
with ESMTP id 2011050612251028-17357 ;
Fri, 6 May 2011 12:25:10 -0400
From: [email protected]
Date: Fri, 6 May 2011 12:25:10 -0400
Message-ID: <[email protected]>
Any thoughts would be greatly appreciated.
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定,也没有简单的方法来亲自测试。
我看到的公共邮件的所有示例的消息格式都为 html - site
(
一些用于测试的文本
)
此外我注意到这一点:
也许这是一个问题。
您是否测试了 API 中编写的方式?
他们使用 StringBuffer:
只是一些想法,到目前为止从未使用过公共邮件...
希望这有帮助!问候,
I am not sure, and got no easy way to test it myself.
All examples i saw for commons-mail had the msg formatted as html - site
(<html><body><p>Some text for testing</p></body></html>)
Furthermore I noticed this:
maybe this is a problem.
Did you tested the way it is written in the API ?
They use a StringBuffer:
Just some thoughts, never worked with commons-mail so far...
Hope this help! Regards,