希望有人能找到我缺少的东西。我正在尝试在 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();
我收到了电子邮件,但它的格式是这样的。还需要注意的是,没有主题,但我显然在我的代码中指定了一个。
------=_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: 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>
任何想法将不胜感激。
干杯