HtmlEmail 未正确呈现 HTML (apache commons)

发布于 2024-11-05 16:43:35 字数 3283 浏览 3 评论 0原文

希望有人能找到我丢失的东西。我正在尝试在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蹲在坟头点根烟 2024-11-12 16:43:36

我不确定,也没有简单的方法来亲自测试。

我看到的公共邮件的所有示例的消息格式都为 html - site (

一些用于测试的文本

此外我注意到这一点:

email.setHtmlMsg("<b>This is a bolded message</b>"); // HTML TEXT
email.setTextMsg("This is a text message"); // NORMAL Text, with no HTML styles

也许这是一个问题。

您是否测试了 API 中编写的方式?
他们使用 StringBuffer:

 StringBuffer msg = new StringBuffer();
 msg.append("<html><body>");
 msg.append("<img src=cid:").append(he.embed(img)).append(">");
 msg.append("<img src=cid:").append(he.embed(png)).append(">");
 msg.append("</body></html>");
 HtmlEmail he = new HtmlEmail();
he.setHtmlMsg(msg.toString());

只是一些想法,到目前为止从未使用过公共邮件...

希望这有帮助!问候,

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:

email.setHtmlMsg("<b>This is a bolded message</b>"); // HTML TEXT
email.setTextMsg("This is a text message"); // NORMAL Text, with no HTML styles

maybe this is a problem.

Did you tested the way it is written in the API ?
They use a StringBuffer:

 StringBuffer msg = new StringBuffer();
 msg.append("<html><body>");
 msg.append("<img src=cid:").append(he.embed(img)).append(">");
 msg.append("<img src=cid:").append(he.embed(png)).append(">");
 msg.append("</body></html>");
 HtmlEmail he = new HtmlEmail();
he.setHtmlMsg(msg.toString());

Just some thoughts, never worked with commons-mail so far...

Hope this help! Regards,

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文