Java HtmlEmail未正确呈现HTML(apache commons)

Java HtmlEmail未正确呈现HTML(apache commons),java,html,email,apache-commons-email,Java,Html,Email,Apache Commons Email,希望有人能找到我丢失的东西。我试图在java应用程序中发送一封简单的HTML电子邮件。我使用commons mail 1.1(通过maven)作为我的邮件库 我使用的代码是: HtmlEmail email = new HtmlEmail(); email.setDebug(true); email.setHostName("my.emailhost.com"); email.addTo("my_gmail_address@gmail.com"); email.setFrom("my_work_

希望有人能找到我丢失的东西。我试图在java应用程序中发送一封简单的HTML电子邮件。我使用commons mail 1.1(通过maven)作为我的邮件库

我使用的代码是:

HtmlEmail email = new HtmlEmail();
email.setDebug(true);
email.setHostName("my.emailhost.com");
email.addTo("my_gmail_address@gmail.com");
email.setFrom("my_work_address@emailhost.com");
email.setSubject("Test Subject");
email.setHtmlMsg("<b>This is a bolded message</b>");
email.setTextMsg("This is a text message");
email.send();
HtmlEmail=newhtmlemail();
email.setDebug(true);
email.setHostName(“my.emailhost.com”);
email.addTo(“我的gmail_address@gmail.com");
email.setFrom(“我的工作_address@emailhost.com");
电子邮件。setSubject(“测试对象”);
email.setHtmlMsg(“这是一条粗体消息”);
email.setTextMsg(“这是一条短信”);
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--
----=\u部分\u 0\u 122395252.1304699110505
内容类型:文本/纯文本;字符集=美国ascii码
内容传输编码:7bit
这是一条短信
------=_零件_0_122395252.1304699110505
内容类型:text/html;字符集=美国ascii码
内容传输编码:7bit
这是一个粗体的信息
------=_零件_0_122395252.1304699110505--
我不确定我做错了什么。我改用gmail发送邮件,它确实发送了,只是格式完全一样。当我查看原始消息时,我看到

Delivered-To: xxxxxxx@gmail.com
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: <xxxxxxx@xxxxxxx.com>
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 xxxxxxx@xxxxxxx.com 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 xxxxxxx@xxxxxxx.com designates x.x.x.x as permitted sender) smtp.mail=xxxxxxx@xxxxxxx.com
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: xxxxxxx@xxxxxxx.com
Date: Fri, 6 May 2011 12:25:10 -0400
Message-ID: <OF8BBF4CBD.70926756-ON85257888.005A31F5@xxxxxxx.com>
交付给:xxxxxxx@gmail.com
收到日期:2011年10月90日前,SMTP id为v11cs143993aga;
2011年5月6日星期五09:25:11-0700(PDT)
收到日期:1997年10月236日,SMTP id为x61mr4380232yhm.476.1304699111088;
2011年5月6日星期五09:25:11-0700(PDT)
返回路径:
收到:来自xxxxxxx.xxxxxxx.com(xxxxxxx.xxxxxxx.com[x.x.x.x])
通过mx.google.com发布,ESMTP id 68si9400486yhl.82.2011.05.06.09.25.10;
2011年5月6日星期五09:25:10-0700(PDT)
收到SPF:pass(google.com:domain of ofxxxxxxx@xxxxxxx.com指定x.x.x.x为允许的发送方)客户端ip=x.x.x.x;
认证结果:mx.google.com;spf=pass(google.com:domain of ofxxxxxxx@xxxxxxx.com将x.x.x.x指定为允许的发件人)smtp.mail=xxxxxxx@xxxxxxx.com
收到:来自xxxxxxx-mac-pro.local([x.x.x.x])
由xxxxxxx.xxxxxxx.com(Lotus Domino发行版8.5.1FP3)
ESMTP id为2011050612251028-17357;
2011年5月6日星期五12:25:10-0400
发件人:xxxxxxx@xxxxxxx.com
日期:2011年5月6日星期五12:25:10-0400
消息ID:
任何想法都将不胜感激


干杯

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

我在commons mail中看到的所有示例都将msg格式化为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
email.setHtmlMsg(“这是一条粗体消息”);//HTML文本
email.setTextMsg(“这是一条短信”);//普通文本,没有HTML样式
也许这是个问题

你有没有测试过它的书写方式 它们使用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());
StringBuffer msg=new-StringBuffer();
msg.追加(“”);
msg.追加(“”);
msg.追加(“”);
msg.追加(“”);
HtmlEmail he=新HtmlEmail();
he.setHtmlMsg(msg.toString());
只是一些想法,到目前为止从未与commons mail合作过

希望这有帮助!问候,