automated mail code throwing javax.mail.AuthenticationFailedException

hi...

i want to generate and send automated mails from my jsp application and had downloaded a code for the same... but now when i run this code it gives me javax.mail.AuthenticationFailedException...can any one pls tell me how to rectify this...plzzz...

here is the code...

import javax.mail.*;

import javax.mail.internet.*;

import java.util.*;

import javax.mail.Authenticator;

import javax.mail.PasswordAuthentication;

public class SendEmail

{

public static void main(String[] args)

{

System.out.println(args.length);

if (args.length != 6)

{

System.out.println("usage: sendmessage <to> <from> <smtphost> <true|false> <subject> <text>");

System.exit(1);

}SendEmail m=new SendEmail();

m.SendMessage(args[0],args[1], args[2], args[3], args[4], args[5]);

}

public static String SendMessage(String emailto, String emailfrom, String smtphost, String emailmultipart, String msgSubject, String msgText)

{

boolean debug = false; // change to get more information

String msgText2 = "multipart message";

boolean sendmultipart = Boolean.valueOf(emailmultipart).booleanValue();

// set the host

Properties props = new Properties();

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

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.username", "ditty@yahoo.com");

props.put("mail.smtp.password", "mypassword");

Authenticator loAuthenticator = new SMTPAuthenticator();

// create some properties and get the default Session

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

session.setDebug(debug);

try

{

// create a message

Message msg = new MimeMessage(session);

// set the from

InternetAddress from = new InternetAddress(emailfrom);

msg.setFrom(from);

InternetAddress[] address =

{

new InternetAddress(emailto)

};

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

msg.setSubject(msgSubject);

if(!sendmultipart)

{

// send a plain text message

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

}

else

{

// send a multipart message// create and fill the first message part

MimeBodyPart mbp1 = new MimeBodyPart();

mbp1.setContent(msgText, "text/plain");

// create and fill the second message part

MimeBodyPart mbp2 = new MimeBodyPart();

mbp2.setContent(msgText2, "text/plain");

// create the Multipart and its parts to it

Multipart mp = new MimeMultipart();

mp.addBodyPart(mbp1);

mp.addBodyPart(mbp2);

// add the Multipart to the message

msg.setContent(mp);

}

Transport transport = session.getTransport("smtp");

transport.connect(smtphost,"ditty@yahoo.com","mypassword");

transport.sendMessage(msg,msg.getAllRecipients());

transport.close();

}

catch(MessagingException mex)

{

mex.printStackTrace();

}

return "Email sent to " + emailto;

}

}

class SMTPAuthenticator extends Authenticator

{

public PasswordAuthentication getPasswordAuthentication()

{

String username = "ditty@yahoo.com";

String password = "mypassword";

return new PasswordAuthentication(username, password);

}

}

[3443 byte] By [Dittya] at [2007-10-2 5:15:44]
# 1

You realise that an AuthenticationFailedException means that you have an incorrect username/password?

To rectify: u

- use a legitimate username/password for the mail server you are using

- you also need a mail server: smtphost to send mail from.

Basically make sure all of this info is correct for you:

// set the host

Properties props = new Properties();

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

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.username", "ditty@yahoo.com");

props.put("mail.smtp.password", "mypassword");

evnafetsa at 2007-7-16 1:18:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

Thanks...but the username and password is my personal yahoo email id ...and is correct... and just to test im sending mail to my friend's account which again belongs to yahoo...

i have downloaded mail.jar and activation.jar....are these sufficient..? can u plzz elobarate more on mail server and smtphost...im a student..and working with jsp for the first time...can u give me an example of correct parameters to be passed, while executing ...i excute it as java SendEmail myfriend@yahoo.com ditty@yahoo.com smtp.mail.yahoo.com true hi hello

Dittya at 2007-7-16 1:18:08 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...