0

I am try to take unread mails from gmail. There are lots of example code and I used them. The problem is, code doesn't work in every area. For example when I was at home the code works but in working area it is not. I think it is about network settings or different ports etc...

I am using the code that is already implemented in this a link. (First answer)

When I run that script at home it works. In my working are, it doesn't and the error message's is at below.

The question is how can i learn the which port should I use ? or Should I do another thing that I miss ?

Any directions, links or codes are appreciated.

com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.gmail.com, 587; timeout -1; nested exception is: java.net.ConnectException: Connection timed out: 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:345) at javax.mail.Service.connect(Service.java:226) at gmailYeni.SendMail.sendFromGMail(SendMail.java:52) at gmailYeni.SendMail.main(SendMail.java:20)

    `Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.TwoStacksPlainSocketImpl.socketConnect(Native Method)
at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source)
at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source)
at java.net.AbstractPlainSocketImpl.connect(Unknown Source)
at java.net.PlainSocketImpl.connect(Unknown Source)
at java.net.SocksSocketImpl.connect(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:297)
at com.sun.mail.util.SocketFetcher.getSocket(SocketFetcher.java:229)
at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1927)
... 5 more

`

Community
  • 1
  • 1
Batuhan B
  • 1,835
  • 4
  • 29
  • 39

1 Answers1

0

It seems you are sending mail from gmail. Then please check if your firewall allows access to gmail. If yes, try changing port# from 25 to 465 and try. But it seems an issue that your firewall is blocking access to gmail.

Dark Knight
  • 8,218
  • 4
  • 39
  • 58
  • in my working area, for security there is lots of firewall and something like that. I can access to gmail from browser but cannot access with java code. – Batuhan B Nov 05 '13 at 11:00
  • 1
    You will unlikely be able to use IMAP and SMTP directly through a highly restrictive corporate network. If they firewall off the ports, you can't connect, and therefore, you can't use them. Gmail in a browser does everything over HTTP via their web servers, so is using completely different methods. – Max Nov 05 '13 at 15:47