简体   繁体   English

Java:有关Apache Commons Mail的问题

[英]Java: Question regarding apache commons mail

I am trying to send an email using Apache commons Email API. 我正在尝试使用Apache Commons Email API发送电子邮件。

I installed hMailServer as my smtp server and created a domain test.com. 我将hMailServer安装为我的smtp服务器,并创建了一个域test.com。 I added an user, 'user1' . 我添加了一个用户'user1'。

I tried to send the mail using the below code 我尝试使用以下代码发送邮件

  public static void sendSimpleMail() throws Exception {
    Email email = new SimpleEmail();
    email.setSmtpPort(25);
    email.setDebug(false);
    email.setHostName("localhost");
    email.setFrom("user1@test.com");
    email.setSubject("Hi");
    email.setMsg("This is a test mail ... :-)");
    email.addTo("abc@gmail.com");
    email.setTLS(true);
    email.send();
    System.out.println("Mail sent!");
}

When my program runs, it prints , "Mail sent!". 当我的程序运行时,它会显示“邮件已发送!”。 But it has been about 30 minutes, but I haven't got the mail in my inbox. 大约30分钟了,但是收件箱中没有邮件。

Is there something I am missing ? 我有什么想念的吗? Is there delay due to network problems ? 是否由于网络问题而延迟?

Update: 更新:

I ran diagnostics and I got the below details. 我运行了诊断程序,并获得了以下详细信息。

在此处输入图片说明

I think the problem might be with outbound port. 我认为问题可能出在端口上。

Can anyone help me figure what is going wrong? 谁能帮助我找出问题所在?

There could be a number of problems. 可能存在许多问题。 Since you didn't get an exception in your Java code, most likely the E-mail has reached your hMailServer instance, but hasn't gotten past that. 由于您的Java代码中没有异常,因此电子邮件很可能已到达您的hMailServer实例,但是还没有超过。 The documentation for hMailServer includes a number of troubleshooting suggestions. hMailServer文档包括许多故障排除建议。

My best guess would be that your ISP (or your local firewall) is blocking outbound port 25. Also, be sure to check your spam folder on gmail. 我的最佳猜测是您的ISP(或您的本地防火墙)阻止了出站端口25。此外,请确保检查gmail上的垃圾邮件文件夹。

Well take a look at the error: "mail.hmailserver.com could not be resolved" (AKA not found). 好看看错误:“无法解决mail.hmailserver.com”(找不到AKA)。 Are you sure that's the correct address? 您确定那是正确的地址吗? Are you sure there's a mail server there? 您确定那里有邮件服务器吗?

BTW unless you have some HOSTS file enteries, that second failed test with "test.com" will never work. 顺便说一句,除非您有一些HOSTS文件输入,否则使用“ test.com”进行的第二次失败测试将永远无法进行。 Use a real mail server 使用真实邮件服务器

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM