我ArrayList
再次发送邮件时遇到问题。程序构建和成功运行大约1个月。但是今天我发现一些重要邮件不是来自我的程序。然后,我开始调试我的代码。让我分享我的发现。
我有Arraylist
一些数据库查询填充;
ArrayList<String> importantlist = new ArrayList<String>();
填充完成后,将其发送Arraylist
到Mail sender方法;
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 ---
真的,我现在很震惊!!我继续调试,这次调试时邮件进入我的邮箱。因为我看到cominglistString
和email
消息框填充这个时候。有时邮件不来。我被卡住了:(
问题解决了。这是本地防火墙问题。防火墙阻止了应用程序计算机和邮件服务器之间的通信。
防火墙重新启动,问题消失了。
感谢您提供所有答案。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句