0

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?

5
  • You add the jars to your build path with your IDE.Are you using Eclipse? Commented Jun 10, 2013 at 6:11
  • Yes I'm using eclipse I don't know where to find the javaee.jar though? I believe I added the mail one Commented Jun 10, 2013 at 6:16
  • Are u under a proxy server? Commented Jun 10, 2013 at 6:35
  • no (Comment too short) Commented Jun 10, 2013 at 6:39
  • Have you tried the SSL version encryption version or instead of smtp.gmail.com try smtp.googlemail,com Commented Jun 10, 2013 at 6:40

3 Answers 3

0

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Yes i've clicked add external jar's but I have no idea where to find the jars
Have you downloaded them to?If you haven't you've got to download the API version you want.Are you on Java EE 5 or 6? For Java EE 5: download.java.net/maven/1/javaee/jars/javaee-api-5.jar For Java EE 6: download.java.net/maven/2/javax/javaee-api/6.0/… For mail.jar: mvnrepository.com/artifact/javax.mail/mail/1.4
im on 6, maybe i need a newer mail version too, where can I find that one?
0

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.

Comments

0

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

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.