SMTP client program gives run-time error - java

I can compile my code but not execute. What could be the reason and how should i sort itI get the following run-time errors.
C:\>java SMTPClient
Exception in thread "main" javax.mail.MessagingException: Could not connect to S
MTP host: smtp.mail.yahoo.com, port: 465;
nested exception is..................etc</b></code>

Please provide the root cause or Stack trace of the Exception.
It may be because you haven't configured Authenticator

probably SMTPClient uses a SMTP protocol, but yahoo uses more secure one like ASMTP. can you post your SMTPClient class here?

The JavaMail FAQ has instructions for connecting to Yahoo mail, as well as debugging tips for when it doesn't work.

The reason is that it cannot connect to the Yahoo Mail Server. I'm unsure of Yahoo's mail port so ensure that the port is correct. Can you post more details? I.e. the nested exception....

Related

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?

550 Access denied - Invalid HELO name

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

Could not connect to SMTP host: {remote-server}, port: {port}, response: -1

I am trying to send mail using java mail api. But exception is come to me with above
message.
Could not connect to SMTP host: {remote-server}, port: {port}, response: -1
What`s mean "response : -1"
I can`t found this code in api manual.
A response code of -1 means that JavaMail failed to get a valid response code from the SMTP server. You can view the relevant source here.
Most likely, you either have your properties set incorrectly or you have a networking issue such as a firewall blocking the connection.
You might try enabling debug mode (session.setDebug(true)). Please post your code if you need further help.

GWT send mail in development mode mail server problem

I am trying to send a mail with gwt and java on the server with the buitin jetty on eclipse but I am getting the following error:
Cannot open and load mail server properties file.
Cannot send email. javax.mail.MessagingException: Could not connect to SMTP host: localhost, port: 25;
nested exception is:
java.net.ConnectException: Connection refused: connect
does someone know what to configure to make it work??
This is not GWT related problem. Test you email sending code in isolation (without GWT and Jetty).
Start with sample code and configure it's parameters to your need. You will also need to use a SMTP server to send emails this way.

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