Sending email: failed to connect - java

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.

Related

Web Service SOAP server was unable to process request

Hi I'm develping a web app in Java for a local bank and they have a SOAP Web Service that my app consumes. The app is deployed on GlassFish 3.1.2 and the web service was generated on .Net (I don't know the specifics, I'm new to the project) and everything is connected through a peer to peer VPN.
Now the issue I have is when I try to log in I get an EJBException:
javax.faces.el.EvaluationException: javax.ejb.EJBException
Caused by: com.sun.xml.ws.fault.ServerSOAPFaultException: Client received SOAP Fault from server: Server was unable to process request. ---> Changes to this object and its sub-objects have been disabled (Exception from HRESULT: 0x8011042A) Please see the server log to find more detail regarding exact cause of the failure.
Now I'm trying to determine what exactly is the problem with the web service, or even better what should the guys at the bank check to determine what's wrong.
If anyone knows or has some ideas on what we should check please let me know. Thanks
Seems to be server problem. Send them exactly time stamp of request and all the request details, and they will probably guide you to the problem

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?

Apache Commons Mail Erroring on Server Contact

I have a Java app that sends email via Apache Commons Email. The app works just find on my development environment, but when I deploy it to the server, I'm getting an error that Commons couldn't connect to the email server.
org.apache.commons.mail.EmailException: Sending the email to the following failed : 255.255.255.255 :587
...Error authenticating with server.
Just to be sure this wasn't my configuration, I've tried on 2 different email providers, 1) Our email company email provider 2) Gmail. Both work on my dev and both fail with the same message on the server.
I've tried several ports and IP combinations. I've turned SSL on and off. I've checked with our email provider. I'm left with a configuration of either the server or the network.
I work remotely so I'm not on the same network as our servers, but I the app works for me even if I am on VPN.
I've used telnet from within the server and I can connect to the email provider on the proper port.
Does anyone have anything else I can try?
Thanks.
Edit
The error I'm getting is an authentication error. Could there be a security setting to prevent the credentials from being passed?
Still sounds like a permission problem. Ports below 1024 are restricted. Start your app with sudo permission.
It appears I was missing 1 line of code.
Assume "email" is my mail object...
email.setSSL(true);
All is working now. I'm not sure why it wasn't working before.

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

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

Categories