0
votes

I am trying to write add sending an email to an application I have written in java, I found a good guide. http://www.mkyong.com/java/javamail-api-sending-email-via-gmail-smtp-example/

But how do I add the javaee.jar and mail.jar dependencies?

I added the dependencies but I get

"Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587; nested exception is: java.net.SocketException: Unrecognized Windows Sockets error: 87: create at sendMail.main(sendMail.java:47) Caused by: javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587; nested exception is: java.net.SocketException: Unrecognized Windows Sockets error: 87: create at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1961) at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:654) at javax.mail.Service.connect(Service.java:317) at javax.mail.Service.connect(Service.java:176) at javax.mail.Service.connect(Service.java:125) at javax.mail.Transport.send0(Transport.java:194) at javax.mail.Transport.send(Transport.java:124) at sendMail.main(sendMail.java:42) Caused by: java.net.SocketException: Unrecognized Windows Sockets error: 87: create at java.net.Socket.createImpl(Unknown Source) at java.net.Socket.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at com.sun.mail.util.SocketFetcher.createSocket(SocketFetcher.java:321) at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:237) at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927) ... 7 more "

Any ideas what is wrong?

3
You add the jars to your build path with your IDE.Are you using Eclipse?AlvinArulselvan
Yes I'm using eclipse I don't know where to find the javaee.jar though? I believe I added the mail oneuser2469373
Are u under a proxy server?AlvinArulselvan
no (Comment too short)user2469373
Have you tried the SSL version encryption version or instead of smtp.gmail.com try smtp.googlemail,comAlvinArulselvan

3 Answers

0
votes

In the Package Explorer view, right-click the project that you want to add a dependency to.

Click Build Path > Configure Build Path. Click the Libraries tab. Complete one of the following tasks:

Click Add JARS if the .jar file is in the current workspace. Click Add External JARS if the .jar file is not in the current workspace.

Select the .jar file that you want. Click OK.

0
votes

Most likely you have a firewall or anti-virus product that's preventing you from connecting.

See the JavaMail FAQ for tips for debugging connection problems.

0
votes

When sending mail through the SMTP protocol, the port should be set to 465. Change your port to 465 and then try again.