sending email with javamail

Hi

I am new to javaMail....And i having a problem with this program.

I getting the following exception when the run the following program

import javax.mail.*;

import javax.mail.internet.*;

import java.util.Properties;

public class MailDemo

{

public static void main(String[] args) throws Exception

{

boolean debug = false;

//Set the host smtp address

Properties props = new Properties();

props.put("mail.smtp.host", "smtp.mail.yahoo.com");

props.put("mail.transport.protocol","smtp");

props.put("mail.smtp.port","25");

// create some properties and get the default Session

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

session.setDebug(debug);

// create a message

Message msg = new MimeMessage(session);

Transport transport = session.getTransport();

// set the from and to address

InternetAddress addressFrom = new InternetAddress("sheshachala5@yahoo.com");

msg.setFrom(addressFrom);

InternetAddress addressTo = new InternetAddress("nebula_228@yahoo.com");

msg.setRecipient(Message.RecipientType.TO, addressTo);

// Optional : You can also set your custom headers in the Email if you Want

msg.addHeader("MyHeaderName", "myHeaderValue");

// Setting the Subject and Content Type

//msg.setSubject(subject);

//msg.setContent(message, "text/plain");

//Transport.send(msg);

msg.setSubject("Testing javamail plain");

msg.setContent("This is a test", "text/plain");

transport.sendMessage(msg,msg.getRecipients(Message.RecipientType.TO));

transport.close();

}

}

I get th following error message:

Exception in thread "main" java.lang.IllegalStateException: Not connected

at com.sun.mail.smtp.SMTPTransport.checkConnected(SMTPTransport.java:151

1)

at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:548)

at MailDemo.main(MailDemo.java:51)

It is a simple program to send a plain email...

Can anyone help me out

Thanks in advance

Deepthi

[2162 byte] By [deepthi_tirunaharirama] at [2007-11-27 8:19:38]
# 1

It's not connected because you never call Transport.connect.

It's not clear from your code why you chose to use the more

complex way of managing the Transport object yourself rather

than just using the static Transport.send method.

You're also setting some properties that don't really need to be

set because they match the default values.

bshannona at 2007-7-12 20:07:49 > top of Java-index,Enterprise & Remote Computing,Enterprise Technologies...