File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Other JSE/JEE APIs and the fly likes Unable to send an email from java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Java » Other JSE/JEE APIs
Bookmark "Unable to send an email from java" Watch "Unable to send an email from java" New topic
Author

Unable to send an email from java

Rakesh Keerthi
Ranch Hand

Joined: Jul 16, 2012
Posts: 144
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
    Bartender

    Joined: Oct 14, 2005
    Posts: 18868
        
        8

    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

    Joined: Jul 16, 2012
    Posts: 144
    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
    Bartender

    Joined: Oct 14, 2005
    Posts: 18868
        
        8

    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

    Joined: Jul 16, 2012
    Posts: 144
    Hi Paul,

    my office uses MS exchange server.

    Thanks
    Ulf Dittmer
    Marshal

    Joined: Mar 22, 2005
    Posts: 42588
        
      65
    So he can give you all the information you need.


    Ping & DNS - my free Android networking tools app
    Nam Ha Minh
    Ranch Hand

    Joined: Oct 31, 2011
    Posts: 498

    Hi Rakesh Keerthi,

    If you are using Gmail SMTP server, make sure you enable SMTP for your Gmail account settings.


    PM Me If You Want to get Urgent Help on Java Programming
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Unable to send an email from java