550 Access denied - Invalid HELO name - java

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

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 :)

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.

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);

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

Related

Sending email with javax.mail, works with gmail but get error with others

I tried the code suggested on this page and it worked really well with gmail, as in the example. I specifically worked with the SSL Authentication Example.
Using the same code but changing the credentials and the SMTP Host, I get the following error:
javax.mail.SendFailedException: Invalid Addresses; nested exception
is: com.sun.mail.smtp.SMTPAddressFailedException: 504 5.5.2
<me#MY-PC>: Sender address rejected: need fully-qualified
address
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1996)
at
com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1240)
at javax.mail.Transport.send0(Transport.java:255) at
javax.mail.Transport.send(Transport.java:124) at
EmailUtil.sendEmail(EmailUtil.java:49) at
EmailSSL.main(EmailSSL.java:56) Caused by:
com.sun.mail.smtp.SMTPAddressFailedException: 504 5.5.2
<me#MY-PC>: Sender address rejected: need fully-qualified
address
at com.sun.mail.smtp.SMTPTransport.rcptTo(SMTPTransport.java:1896)
... 5 more
What bugs me is that the sender's address is now my local PC's address, even if the one specified in the code is not.
Why would the exact same code would work with gmail and not with another host?
Thanks for reading!
Vincent
Different servers have different requirements.
This Gmail help page might be useful.
See also the JavaMail FAQ entry for Gmail.

Failed sending email with java program via smtp and ssl

I am just trying to send an email form java code. But I am getting exception like this:
"java.lang.RuntimeException: javax.mail.MessagingException:
Could not connect to SMTP host:smtp.gmail.com, port: 465, response: -1."
I have set the following properties:
mail.smtp.host
mail.smtp.socketFactory.port
mail.smtp.auth
mail.smtp.port
What is the reason for this exception?
Please help me. Thanks in advance.
You could probably try this example to sort it out problem -
Java send mail through gmail
Looks like you haven't found the JavaMail FAQ. These entries might help:
How do I debug problems connecting to my mail server?
How do I configure JavaMail to work through my proxy server?

JavaMail API connection to Mercury Mail server error

I am trying to connect to Mercury mail server with a java application and I am using JavaMail api. The connection is not successful and I’m getting this error in the log:
EHLO x.x.x.x
554 Invalid HELO format
Which means that it connects to the server but the helo format is not something that sever likes. I've tired to debug it and I got to this code in JavaMail “SMTPTransport” class which says:
serverOutput.write(cmdBytes);
serverOutput.write(CRLF);
serverOutput.flush();
and according to code:
private static final byte[] CRLF = { (byte)'\r', (byte)'\n' };
which seems consistent with RFC 821
I know that on windows \n has different meaning but I am not sure if this really is the root of problem? If it not then what can cause this?
I checked mail server with mail client and it works fine and I checked the code with James mails server and it also works fine!
JavaMail API version is: 1.4.5 (latest release)
Mercury/32 : 4.7
I did a Google search on 554 Invalid HELO format and got a ton of hits about your specific Mercury problem. It's a bug.
http://community.pmail.com/forums/thread/4136.aspx
http://www.mantisbt.org/bugs/view.php?id=9645
http://ellislab.com/codeigniter/forums/viewthread/153130/
etc...
You might need to check the logs on the server to figure out what it's really complaining about, but... One thing you can try is setting the mail.stmp.localhost property to the correct DNS host name for your machine. From the debug output it looks like your machine is unable to determine its own name and so is sending the IP address instead.
For me in a web project the PHPMailer() class was forcing Auth. Changing the Auth to false fixed it. Maybe check similar option for setting Auth to false in your language.
This is what I changed in my PHP code from true to false and adding sendmail_from in the php.ini file
$mail = new PHPMailer();
$mail->SMTPAuth = false;

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

Sending email: failed to connect

I am using java to send mail.
I want to set the from mail id to xyz#chatmeter.com.
When i am using that for sending mail the following exception is generated..
Exception in thread "main" javax.mail.AuthenticationFailedException: failed to connect
at javax.mail.Service.connect(Service.java:322)
at javax.mail.Service.connect(Service.java:172)
at javax.mail.Service.connect(Service.java:121)
at javax.mail.Transport.send0(Transport.java:190)
at javax.mail.Transport.send(Transport.java:120)
at sendmailtoclient.SendSMTP.sendMail(SendSMTP.java:125)
at sendmailtoclient.SendSMTP.main(SendSMTP.java:153)
I have used the correct password for the mail account.
although it I have used the xyz#gmail.com successfully.
If you have code please post to me.
Please help me.
Thanks in advance.
It looks like your credentials are wrong or not accepted by gmail.
You need SMTP server for sending mail. You can use one installed on your own machine
One free one is here.
Also check if you have added activation.jar
Mostly this error occurs from not having activation.jar and mail.jar on your classpath. Add them as a maven dependency or add in WEB-INF/lib and it should be fine.

Categories