1

Good day SO people!

I am trying to send an email through java code by using the gmail smtp server for quite some time now and I'm still unlucky to get success. I tried to execute the codes from this tutorial

and I am getting an exception. Below is the log trace:

javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 465;
  nested exception is:
    java.net.ConnectException: Connection refused: connect
    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 ph.net.poolbeta.emailer.EmailDriver.sendEmailSSL(EmailDriver.java:108)
    at ph.net.poolbeta.emailer.EmailDriver.main(EmailDriver.java:27)
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
    at java.net.Socket.connect(Socket.java:529)
    at java.net.Socket.connect(Socket.java:478)
    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)
    ... 8 more

I've googled the connection exception error and I've tried some suggestions namely:

  1. ping smtp.gmail.com --> successful.
  2. telnet smtp.gmail.com 'port' --> unsuccessful. I've tried 465 and 587

Is there something that still need to do regarding network? Please help me to resolve this issue. Thanks in advance.

Oneb
  • 375
  • 1
  • 10
  • 21
  • Did you try searching the site first, I'm sure this question has being asked many times before. Have you tried [this](http://stackoverflow.com/questions/46663/how-to-send-an-email-by-java-application-using-gmail-yahoo-hotmail) or [this](http://dunithd.wordpress.com/2009/10/22/send-email-using-javamail-api-and-your-gmail-account/)? – MadProgrammer Jul 25 '13 at 07:33
  • Many networks, especially company networks, do not allow you to connect to "unusual" ports like 25, 465 or 587. I'm afraid you'll have to contact your system admin. – mthmulders Jul 25 '13 at 07:33
  • @MadProgrammer Yes, he has tried your first link, it was already linked in the question. – mthmulders Jul 25 '13 at 07:34
  • @MadProgrammer yes sir I did searched the site first. – Oneb Jul 25 '13 at 07:38
  • @mthmulders good day! so you mean if i try to execute this using my personal computer this would run perfectly? – Oneb Jul 25 '13 at 07:38
  • 1
    At least its worth a try. Can't really tell what your ISP allows, obviously. – mthmulders Jul 25 '13 at 07:40
  • @mthmulders My understanding is that port 465 and 587 are from the google smtp server in which I'm trying to connect. Am I correct? So the said ports should not necessarily be open in my machine? – Oneb Jul 25 '13 at 07:48
  • Indeed, your machine doesn't have to listen on those ports. However, the network you're connected with should *allow* you to contact these ports on a remote machine, for example smtp.gmail.com. – mthmulders Jul 25 '13 at 08:04

0 Answers0