James Server connection failure exception

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2009-09-26T18:03:17Z Indexed on 2010/03/19 3:01 UTC
Read the original article Hit count: 827

Filed under:
|
|

Hi,

I'm trying to connect Javamail application to James server, but I'm getting

javax.mail.MessagingException: Could not connect to SMTP host:localhost, port:4555; nested exception is: java.net.SocketException: Invalid arguent: connect

Here's the code, which is creating a little problem for me:

import java.security.Security;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;

public class mail  {

public static void main(String[] argts)
{
Security.addProvider(new com.sun.net.ssl.internal.ssl.Provider());


       String mailHost = "your.smtp.server";



        String to = "blue@localhost";



        String from = "red@localhost";
        String subject = "jdk";
        String body = "Down to wind";

        if ((from != null) && (to != null) && (subject != null)  && (body != null)) // we have mail to send
        {

        try {


            //Get system properties
            Properties props = System.getProperties();


            props.put("mail.smtp.user", "red");
    		props.put("mail.smtp.host", "localhost");
    		props.put("mail.debug", "true");
    		props.put("mail.smtp.port", 4555);


    		props.put("mail.smtp.socketFactory.port", 4555);
    		props.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    		props.put("mail.smtp.socketFactory.fallback", "false");

            Session session = Session.getInstance(props,null);


            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress(from));
            message.setRecipients(Message.RecipientType.TO, new InternetAddress[] { new InternetAddress(to) });
            message.setSubject(subject);
            message.setContent(body, "text/plain");
            message.setText(body);
            Transport.send(message);


            System.out.println("<b>Thank you.  Your message to " + to + " was successfully sent.</b>");

        } catch (Throwable t) {
           System.out.println("Teri maa ki "+t);
        }


        }

    }




}

Thanks in advance. :)

© Stack Overflow or respective owner

Related posts about java

Related posts about javamail