Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Unable to send an email from java

 
Ranch Hand
Posts: 153
  • Likes 1
  • 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
     
    Marshal
    Posts: 25798
    69
    Eclipse IDE Firefox Browser MySQL Database
    • 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: 153
    • 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
    Marshal
    Posts: 25798
    69
    Eclipse IDE Firefox Browser MySQL Database
    • 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: 153
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Hi Paul,

    my office uses MS exchange server.

    Thanks
     
    Rancher
    Posts: 43016
    76
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    So he can give you all the information you need.
     
    Ranch Hand
    Posts: 530
    Hibernate Eclipse IDE Java
    • 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.
     
    You’ll find me in my office. I’ll probably be drinking. And reading this tiny ad.
    Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
      Bookmark Topic Watch Topic
    • New Topic