2

I am using apace common mail API for sending html emails. following is my code.

public void sendHTMLMail(String to, String subject, String message , String from) throws EmailException
    {

          HtmlEmail email = new HtmlEmail();
          email.setHostName(SMTP_HOST_NAME);
          email.addTo(to);
          email.setFrom(from, "just-flick");
          email.setSubject(subject);
          email.setSmtpPort(25);
          email.setHtmlMsg(message);
          email.setTextMsg("Your email client does not support HTML messages");
          email.send();

    }

But while running the program I am getting following error.

Exception in thread "main" org.apache.commons.mail.EmailException: Sending the e
mail to the following server failed : mail.just-flick.com:25
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1242)
    at org.apache.commons.mail.Email.send(Email.java:1267)
    at bseller.mail.SendMail.sendHTMLMail(SendMail.java:105)
    at bseller.mail.SendMail.main(SendMail.java:31)
Caused by: com.sun.mail.smtp.SMTPSendFailedException: 550 Access denied - Invali
d HELO name (See RFC2821 4.1.1.1)

    at com.sun.mail.smtp.SMTPTransport.issueSendCommand(SMTPTransport.java:1388)
    at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:959)
    at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:583)
    at javax.mail.Transport.send0(Transport.java:169)
    at javax.mail.Transport.send(Transport.java:98)
    at org.apache.commons.mail.Email.sendMimeMessage(Email.java:1232)
    ... 3 more

Please help me to configure this problem.

Thanks

5
  • 2
    You didn't greet the server correctly :(
    – user166390
    Dec 17, 2011 at 4:37
  • Hi thanks for answering, please help me for this.I am new for SMTP server configuration.
    – Pedantic
    Dec 17, 2011 at 4:50
  • 1
    Perhaps slightly related stackoverflow.com/questions/4934373/…
    – user166390
    Dec 17, 2011 at 5:00
  • Remember, you can always "telnet" into the SMTP server and try issuing HELO commands to see what works/fails.
    – user166390
    Dec 17, 2011 at 5:01
  • 4
    "Your email client does not support HTML messages" is wrong, it should be "Your email client is configured to prefer what you prefer instead of what we prefer you to prefer".
    – tripleee
    Sep 6, 2012 at 9:06

5 Answers 5

4

I've faced the same problem, and when i pass the name of client host everything became ok i've add this line in my code:

props.put("mail.smtp.localhost", client or host name which connect to mail server);

Good Luck :)

2

This should be handled by the administrator of your mail server, not by you. Talk to whoever told you to connect to that mail server.

2
  • But when I am using normal java API its working fine, but when I am using common-mail API of Apache, its not working. I am pretty sure some additional configuration I need to do. But not sure what configuration. thanks
    – Pedantic
    Dec 17, 2011 at 5:04
  • The administrator of the mail server will know. It's the mail server that's rejecting your access. Dec 17, 2011 at 5:05
2

Maybe this will help:

email.getMailSession().getProperties().setProperty("mail.smtp.localhost", "www.example.com");

Of course replace www.example.com with the domain name of your host from where you send the mail.

However, as David Schwartz wrote, your mail configuration is not perfect either. Nowdays we do not submit mails to port 25. Port 587 is used for submission, which has more relaxed rules, although it may be necessary to authenticate yourself if your IP address is not white listed. Follow the link which was given by pst in his comment.

It is strange that JavaMail alone works, while Apache Commons Email does not, because I guess Commons Email also used JavaMail. This may indicate a bug somewhere but it would require further investigation.

One of your problem is that you do not know the exact HELO name you are sending. The following code may help to determine it, otherwise call your mail administrator (especially because he may advise you on port 587).

email.getMailSession().setDebug(true);
0
0

I was getting same error, it was fixed after enabling below properties:

spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
spring.mail.properties.mail.smtp.auth=true
0

I fixed the issue as: if the from email adress's server part is xyz.com e.g([email protected]) then add this property

props.put("mail.smtp.localhost", "xyz.com");

Worked perfectly with me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.