• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unable to send an email from java

 
Rakesh Keerthi
Ranch Hand
Posts: 152
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am writing a program to send an email from java but i'm unable to send it i'm getting an error. the code and details are as below.


while executing this i get the below error.

  • Exception in thread "main" java.lang.RuntimeException: javax.mail.SendFailedException: Sending failed;
    nested exception is:
    javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
    nested exception is:
    java.net.ConnectException: Connection timed out: connect
    at mail_j.PlainTextEmailSender.main(PlainTextEmailSender.java:39)
    Caused by: javax.mail.SendFailedException: Sending failed;
    nested exception is:
    javax.mail.MessagingException: Could not connect to SMTP host: smtp.gmail.com, port: 587;
    nested exception is:
    java.net.ConnectException: Connection timed out: connect
    at javax.mail.Transport.send0(Transport.java:219)
    at javax.mail.Transport.send(Transport.java:81)
    at mail_j.PlainTextEmailSender.main(PlainTextEmailSender.java:34)
    Java Result: 1
    BUILD SUCCESSFUL (total time: 42 seconds)


  • i'm getting the same error even if i use port number 587 and 25
    Thanks
     
    Paul Clapham
    Sheriff
    Pie
    Posts: 20170
    24
    MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    The error message says that the code can't connect to that remote computer. Usually that is because there is no physical connection between the two computers, or else because there is a firewall or proxy or some other component which blocks the connection.

    So check your network connectivity.
     
    Rakesh Keerthi
    Ranch Hand
    Posts: 152
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Thanks for your reply Paul.
    yes my office uses a proxy for internet conectivity. how do i solve this issue over there. i know what the proxy ip address is.

    Thanks
     
    Paul Clapham
    Sheriff
    Pie
    Posts: 20170
    24
    MySQL Database
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    You are doing this for work? Then your network manager should be able to help you get connected, assuming it's a work project. Although I'm a bit surprised your office doesn't have its own e-mail server which you could use.
     
    Rakesh Keerthi
    Ranch Hand
    Posts: 152
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Paul,

    my office uses MS exchange server.

    Thanks
     
    Ulf Dittmer
    Rancher
    Pie
    Posts: 42966
    73
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So he can give you all the information you need.
     
    Nam Ha Minh
    Ranch Hand
    Posts: 502
    Eclipse IDE Firefox Browser Windows
    • 0
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Rakesh Keerthi,

    If you are using Gmail SMTP server, make sure you enable SMTP for your Gmail account settings.
     
    It is sorta covered in the JavaRanch Style Guide.
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic