我有一个通过电子邮件发送确认的应用程序。电子邮件部分使用 Commons Mail API。发送邮件的简单代码如下所示;
import org.apache.commons.mail.*;
...
// Create the attachment
EmailAttachment attachment = new EmailAttachment();
attachment.setURL(new URL("http://cashew.org/doc.pdf"));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Testing attach");
attachment.setName("doc.pdf");
// Create the email message
MultiPartEmail email = new MultiPartEmail();
email.setHostName("mail.cashew.com");
email.addTo("ben@cashew.org");
email.setFrom("lot@cashew.org");
email.setSubject("Testing);
email.setMsg("testing message");
// add the attachment
email.attach(attachment);
// send the email
email.send();
我的问题是,当我从 Eclipse 执行此应用程序时,我收到带有附件的电子邮件,没有任何问题。但是当我将应用程序部署到 Tomcat 服务器时(我有
尝试了第 5 版和第 6 版都没有乐趣),电子邮件的发送内容如下;
------=_Part_0_25002283.1275298567928
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
testing
Regards,
los
------=_Part_0_25002283.1275298567928
Content-Type: application/pdf; name="doc.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="doc.pdf"
Content-Description: Testing attach
JVBERi0xLjQNJeLjz9MNCjYzIDAgb2JqDTw8L0xpbmVhcml6ZWQgMS9MIDMxMzE4Mi9PIDY1L0Ug
Mjg2NjY5L04gMS9UIDMxMTgwMi9IIFsgMjgzNiAzNzZdPj4NZW5kb2JqDSAgICAgICAgICAgICAg
DQp4cmVmDQo2MyAxMjcNCjAwMDAwMDAwMTYgMDAwMDAgbg0KMDAwMDAwMzM4MCAwMDAwMCBuDQow
MDAwMDAzNTIzIDAwMDAwIG4NCjAwMDAwMDQzMDcgMDAwMDAgbg0KMDAwMDAwNTEwOSAwMDAwMCBu
DQowMDAwMDA2Mjc5IDAwMDAwIG4NCjAwMDAwMDY0MTAgMDAwMDAgbg0KMDAwMDAwNjU0NiAwMDAw
MCBuDQowMDAwMDA3OTY3IDAwMDAwIG4NCjAwMDAwMDkwMjMgMDAwMDAgbg0KMDAwMDAwOTk0OSAw
MDAwMCBuDQowMDAwMDExMDAwIDAwMDAwIG4NCjAwMDAwMTIwNTkgMDAwMDAgbg0KMDAwMDAxMjky
MCAwMDAwMCBuDQowMDAwMDEyOTU0IDAwMDAwIG4NCjAwMDAwMTI5ODIgMDAwMDAgbg0KMDAwMDAx
.......
CnN0YXJ0eHJlZg0KMTE2DQolJUVPRg0K
------=_Part_0_25002283.1275298567928--
我还注意到的一件事是,标题信息不显示 TO 和 Subject 值。嗯,很诡异。我必须指出,上面不是 DEBUG 生成的,它是我的 Outlook 客户端收到的实际消息。
有人能帮助我吗!
更新:该应用程序非常简单。附加一个部分和文本消息也作为一个单独的部分。
public final void Email(String from, String to, String cc,
String subject, String message, String doc, String bcc) {
MultiPartEmail email = new MultiPartEmail();
try {
if (!(doc == null)) {
EmailAttachment attachment = new EmailAttachment();
attachment.setURL(new URL("http://cashew.org/doc.pdf"));
attachment.setDisposition(EmailAttachment.ATTACHMENT);
attachment.setDescription("Testing attach");
attachment.setName("doc.pdf");
email.attach(attachment);
}
email.setHostName("mail.cashew.com");
// [ Set Header details
email.setTo(getAddress(to));
email.setFrom(from);
email.setSubject(subject);
if (!(cc == null)) {
eEmail.setCc(getAddress(cc));
}
if (!(bcc == null)) {
email.setBcc(getAddress(bcc));
}
email.setMsg(message);
email.send();
} catch (Exception ex) {
ex.printStackTrace();
}
}
有谁知道发生了什么?