javax.mail.AuthenticationFailedException
843834Aug 29 2008 — edited Aug 29 2008hi
when i try to use the gmail smtp host i am getting this type of exception plz send the solution
this is my code
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class Ex {
/**
* @param args
*/
public void postMail( String recipients, String subject, String message , String from) throws MessagingException
{try{
boolean debug = false;
//Set the host smtp address
Properties props = new Properties();
props.put("mail.smtp.host", "smtp.gmail.com");
// 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);
// set the from and to address
InternetAddress addressFrom = new InternetAddress(from);
msg.setFrom(addressFrom);
InternetAddress addressTo = new InternetAddress(recipients);
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");
System.out.println("send");
Transport.send(msg);
}catch(Exception e){
System.out.println(e);
}
}
public static void main(String[] args) throws MessagingException {
Ex ex=new Ex();
ex.postMail("ramangoud.lmca@gmail.com","mail","test mail","ramangoud.lmca@gmail.com");
}
}
plz help me
thanku