0

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.

enter image description here

I think the problem might be with outbound port.

Can anyone help me figure what is going wrong?

centic
  • 15,565
  • 9
  • 68
  • 125
user2434
  • 6,339
  • 18
  • 63
  • 87
  • Did you test your mail server can actually send any email and the target address is correct? AFAIK it doesn't return an error if it gets a bounce or something similar. – Thomas Aug 02 '11 at 11:47
  • In the diagnostics you've added the first error indicates "The hostname mail.hmailserver.com" could not be resolved. That sounds like a DNS look-up problem, and so you might have more fundamental issues. If you go to a command prompt, can you "ping mail.hmailserver.com"? Whether or not ping works, it should indicate the IP address for mail.hmailserver.com. (That name resolves to "83.169.11.240" for me currently.) – kaliatech Aug 02 '11 at 14:31
  • "Ping request could not find host mail.hmailserver.com. Please check the name and try again ". How can we fix it? – user2434 Aug 02 '11 at 14:48
  • It sounds as if your workstation does not have a DNS name server configured. If that's true, then I assume you also can not browse the Internet in Internet Explorer from that workstation, correct? If so, you will need to either configure DNS or statically map all IPs (in the hosts file) to which you might send an E-mail. – kaliatech Aug 02 '11 at 19:37
  • I can browse the internet from my work station. – user2434 Aug 03 '11 at 05:37
  • I'm at a loss then. Perhaps your browser is configured to use a proxy that provides DNS services? The 1st thing that happens when you ping, is that your OS tries to resolve the domain name to an IP address. You indicated above that the OS wasn't able to do that for mail.hmailserver.com. So either DNS is not configured, or your DNS provider could not resolve mail.hmailserver.com for some reason. Based on that though, I think you have more fundamental problems than just hmailserver not working, but I can't be positive. – kaliatech Aug 03 '11 at 14:21

2 Answers2

0

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.

kaliatech
  • 17,579
  • 5
  • 72
  • 84
0

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

TheLQ
  • 14,830
  • 14
  • 69
  • 107