Could Not Connect To SMTP Host Connection Failed -- Software caused connection abort: connect

Discussion in 'Java' started by kishore@novelteam.com, Nov 16, 2005.

  1. Guest

    Hi All,

    Great to have this discussion group which is helping to clear the
    issues.

    Thanks in advance to all.

    I am having strange exception when trying to send email through java. I
    am using my mail server hostname to connect it. My mail server is SMTP
    server.
    When I tried to ping the IP Address it is fine. I tried to execute the
    same in another machine. The result is same.

    The exception I am getting is this way.

    javax.mail.MessagingException: Could not connect to SMTP host:
    <hostname>, port: 25;
    nested exception is:
    java.net.SocketException: Software caused connection abort: connect
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1008)
    at
    com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:197)
    at javax.mail.Service.connect(Service.java:233)
    at javax.mail.Service.connect(Service.java:134)
    at javax.mail.Service.connect(Service.java:86)
    at com.sun.mail.smtp.SMTPTransport.connect(SMTPTransport.java:104)

    I googled about this issue, but I couldn't get the exact idea and
    solution to overcome this exception. My code looks like this.

    package sendingmail;

    import java.util.Properties;
    import javax.mail.Session;
    import javax.mail.Message;
    import javax.mail.Transport;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.InternetAddress;
    import java.util.Date;
    import javax.mail.MessagingException;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.Multipart;
    import javax.mail.internet.MimeMultipart;
    import javax.activation.FileDataSource;
    import javax.activation.DataHandler;

    public class SendingMailMultipart
    {
    private static String HostName = "<HostName>";
    private static String FromAddress = "";
    private static String ToAddress = "";


    public SendingMailMultipart()
    {
    SendEmail();
    }

    protected void SendEmail()
    {
    Properties props = new Properties();
    //props.put("mail.transport.protocol", "smtp");
    props.put("mail.smtp.host",HostName);
    //props.put("mail.debug","true");

    Session session = Session.getInstance(props);
    try
    {
    Transport trans = session.getTransport("smtp");
    trans.connect();

    Message msg = new MimeMessage(session);
    msg.setFrom(new InternetAddress(FromAddress));
    InternetAddress[] Address = {new
    InternetAddress(ToAddress)};
    msg.setRecipients(Message.RecipientType.TO,Address);

    msg.setRecipients(Message.RecipientType.CC,InternetAddress.parse(ToAddress,true));

    msg.setRecipients(Message.RecipientType.BCC,InternetAddress.parse(ToAddress,false));
    msg.setSubject("Test Mail Using Java Mail Multipart");
    msg.setSentDate(new Date());

    setContentOfMsg(msg);
    msg.saveChanges();
    trans.sendMessage(msg,Address);

    setMultiPartContent(msg);
    msg.saveChanges();
    trans.sendMessage(msg,Address);

    setFileAttachedToMail(msg,"D:\\Kishore\\NOTEPADS\\My
    Details.txt");
    msg.saveChanges();
    trans.sendMessage(msg,Address);
    }
    catch(Exception ex)
    {
    ex.printStackTrace();
    }
    }

    private void setContentOfMsg(Message msg)
    {
    try
    {
    String Content = "Hi This Is sending you mail through Java.";
    msg.setText(Content);
    msg.setContent(Content,"text/plain");
    }
    catch(MessagingException ex)
    {
    ex.printStackTrace();
    }
    }

    private void setMultiPartContent(Message msg)
    {
    try
    {
    MimeBodyPart MBP1 = new MimeBodyPart();
    MBP1.setText("Hai Hai Hai Hai Hai Hai Hai Hai Hai Hai Hai
    Hai Hai Hai Hai Hai " +
    "This is part one of a test multipart e-mail");

    MimeBodyPart MBP2 = new MimeBodyPart();
    MBP2.setText("Second Part","us-ascii");

    Multipart MP = new MimeMultipart();
    MP.addBodyPart(MBP1);
    MP.addBodyPart(MBP2);

    msg.setContent(MP);
    }
    catch(MessagingException ex)
    {
    ex.printStackTrace();
    }
    }

    private void setFileAttachedToMail(Message msg,String FileName)
    {
    try
    {
    MimeBodyPart MBP1 = new MimeBodyPart();
    MBP1.setText("This is the first part in FileAttachment
    MimeBodyPart1");

    MimeBodyPart MBP2 = new MimeBodyPart();
    FileDataSource FDS = new FileDataSource(FileName);
    MBP2.setDataHandler(new DataHandler(FDS));
    MBP2.setFileName(FDS.getName());

    Multipart MP = new MimeMultipart();
    MP.addBodyPart(MBP1);
    MP.addBodyPart(MBP2);

    msg.setContent(MP);
    }
    catch(MessagingException ex)
    {
    ex.printStackTrace();
    }
    }

    public static void main(String[] args)
    {
    SendingMailMultipart sendingmailmultipart = new
    SendingMailMultipart();
    }
    }

    Can any one kindly suggest what is that going wrong in this snippet
    code, if you have come across the same scenario. Please help out in
    this regards.

    regards,
    kishore.
     
    , Nov 16, 2005
    #1
    1. Advertising

  2. Re: Could Not Connect To SMTP Host Connection Failed -- Software

    wrote:
    > I am having strange exception when trying to send email through java. I
    > am using my mail server hostname to connect it. My mail server is SMTP
    > server.
    > When I tried to ping the IP Address it is fine. I tried to execute the
    > same in another machine. The result is same.

    Be aware that Ping does not contact port 25 (the SMTP port). Are you
    really sure, that an SMTP server is running on your remote host? Is a
    firewall involved which might blocks your traffic?
    You can check all this manually by using telnet, instead of running your
    Java program. See <http://www.activexperts.com/activemail/telnet/> for how.
    >
    > The exception I am getting is this way.
    >
    > javax.mail.MessagingException: Could not connect to SMTP host:
    > <hostname>, port: 25;
    > nested exception is:
    > java.net.SocketException: Software caused connection abort: connect


    --
    "Thomas:Fritsch$ops:de".replace(':','.').replace('$','@')
     
    Thomas Fritsch, Nov 16, 2005
    #2
    1. Advertising

  3. Roedy Green Guest

    On 16 Nov 2005 05:55:12 -0800, wrote, quoted or
    indirectly quoted someone who said :

    >javax.mail.MessagingException: Could not connect to SMTP host:
    ><hostname>, port: 25;


    you should have some code like this:

    Properties props = System.getProperties();
    if ( CustConfig.needPasswordToSend )
    {
    props.setProperty ( "mail.smtp.auth", "true" );
    }
    // Get a Session object
    session = Session.getDefaultInstance( props, null );
    session.setDebug( CustConfig.DEBUGGING );

    // Get a Store object, all mail on server
    store = session.getStore( receiveProtocol );

    // Connect

    store.connect( receiveHost, receivePort, receiveLoginID,
    receivePassword );

    // or

    Transport transport = session.getTransport( sendProtocol );
    transport.connect( sendHost, sendPort, sendLoginID,
    sendPassword );




    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 16, 2005
    #3
  4. Roedy Green Guest

    On Wed, 16 Nov 2005 15:04:03 GMT, Thomas Fritsch
    <> wrote, quoted or indirectly quoted
    someone who said :

    >Be aware that Ping does not contact port 25 (the SMTP port). Are you
    >really sure, that an SMTP server is running on your remote host? Is a
    >firewall involved which might blocks your traffic?


    make sure an ordinary mail program like Eudora works first.
    --
    Canadian Mind Products, Roedy Green.
    http://mindprod.com Java custom programming, consulting and coaching.
     
    Roedy Green, Nov 16, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. jaco
    Replies:
    0
    Views:
    1,803
  2. Replies:
    2
    Views:
    7,110
    Thomas Hawtin
    Aug 22, 2005
  3. sushali
    Replies:
    0
    Views:
    6,710
    sushali
    Sep 1, 2005
  4. Replies:
    1
    Views:
    4,425
  5. Jean-Pierre Bergamin

    Socket error: 10053 software caused connection abort

    Jean-Pierre Bergamin, Apr 14, 2004, in forum: Python
    Replies:
    7
    Views:
    46,433
    Maheshbabu
    Apr 7, 2014
Loading...

Share This Page