通过commons-email-1.3.2发送邮件

时间:2014-07-28 10:09:46

标签: java arraylist sendmail

我再次遇到ArrayList邮件问题。计划建设和成功工作约1个月。但是今天我发现了一些不是来自我的程序的重要邮件。然后我开始调试我的代码。让我分享一下我的发现。

我从一些数据库查询填充了Arraylist;

ArrayList<String> importantlist = new ArrayList<String>();

填写完成后,我将此Arraylist发送给邮件发件人方法;

if (importantlist.size() > 0) {
    sendMail(importantlist);
}

sendMail方法;

public void sendMail(ArrayList cominglist) throws Exception {
    StringBuilder b = new StringBuilder();
    for(Object coming: cominglist)
        b.append(coming).append("\n");     
    String cominglistString = b.toString(); 
    Email email = new SimpleEmail();
    email.setHostName("hostname here");
    email.setSmtpPort(587);
    email.setAuthentication("mail sender user here","userpasswordhere");
    email.setSSLOnConnect(false);
    email.setFrom("mail sender address here");
    email.setSubject("Example important list");
    email.setMsg("Example important List body;\n"+cominglistString);
    email.addTo("receiver user here");
    email.addTo("receiver user here");
    email.send();
    System.out.println("success");
} 

当我调试此方法时,当光标到达null时,我看到消息为email.send();但该程序成功运行并向用户发送大约1个月的列表。

如果我尝试另一个sendMail方法,就像下面一样,邮件成功地进入我的邮箱;

public void sendMail2() throws Exception {
    Email email = new SimpleEmail();
    email.setHostName("hostname here");
    email.setSmtpPort(587);
    email.setAuthentication("mail sender user here","userpasswordhere");
    email.setSSLOnConnect(false);
    email.setFrom("mail sender address here");
    email.setSubject("Example simple mail");
    email.setMsg("Example simple mail body;\n");
    email.addTo("receiver user here");
    email.addTo("receiver user here");
    email.send();
    System.out.println("success");
} 

--- ---编辑

email.setMsg("Example important List body;\n"+cominglistString); line edited.

是的,我的名单大于0我确定。

有什么想法吗?

---编辑2 ---

我现在真的很震惊!!我在调试的时候继续调试并邮寄到我的邮箱。因为我这次看到cominglistStringemail消息框已填充。邮件有时候不会出现。我卡住了:(

1 个答案:

答案 0 :(得分:0)

解决了问题。这是本地防火墙问题。应用程序计算机和邮件服务器之间的防火墙阻止通信。

防火墙重新启动,问题就消失了。

感谢所有答案。

相关问题