SMTP test connection

Hi, I am new to javamail api. I want to test SMTP connection. In my form I am taking email address, server address, username and password from the user. Now I want test whether the server address is exists or not.Thanks in advanced.
[253 byte] By [sushiljavascreena] at [2007-10-2 4:34:10]
# 1

Hello,

Use this code.

public static void sendMail(String to, String from, String subject, String message) throws Exception

{

//Create properties and session.

Properties props = new Properties();

props.put("mail.smtp.host", "servername");

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

session.setDebug(false);

try

{

//Create a message

Message msg = new MimeMessage(session);

msg.setFrom(new InternetAddress(from));

InternetAddress[] address = (InternetAddress[]) InternetAddress.parse(to);

msg.setRecipients(Message.RecipientType.TO, address);

msg.setSubject(subject);

msg.setSentDate( new Date() );

msg.setText(message);

Transport.send(msg);

}

catch( Exception e)

{

throw e;

}

}

Thanks and regards,

Pazhanikanthan. P

pazhanikanthana at 2007-7-16 0:06:09 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...