简体   繁体   中英

Java: Question regarding apache commons mail

I am trying to send an email using Apache commons Email API.

I installed hMailServer as my smtp server and created a domain test.com. I added an user, '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.

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. The documentation for hMailServer includes a number of troubleshooting suggestions.

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.

Well take a look at the error: "mail.hmailserver.com could not be resolved" (AKA not found). 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. Use a real mail server

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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