palavi 0 Junior Poster in Training

Hi All,

I m trying to send a simple mail... but not able to send because of this exception

thread "main" javax.mail.AuthenticationFailedException:

and the problem is in this line

here is the simple java class for sending mail

public class SendMailUsingAuthentication
{

  private static final String SMTP_HOST_NAME = "tx.technoinfo.in";
  private static final String SMTP_AUTH_USER = "pallavi.pm";
  private static final String SMTP_AUTH_PWD  = "abcdefs";

  private static final String emailMsgTxt      = "Body:Test Mail .";
  private static final String emailSubjectTxt  = "Subject:Test Mail .";
  private static final String emailFromAddress = "pmj@sfd.com";

  // Add List of Email address to who email needs to be sent to
  private static final String[] emailList = {"pallavi.pm@techniinfo.in", "nandhini.k@techniinfo.in"};

  public static void main(String args[]) throws Exception
  {
    SendMailUsingAuthentication smtpMailSender = new SendMailUsingAuthentication();
    smtpMailSender.postMail( emailList, emailSubjectTxt, emailMsgTxt, emailFromAddress);
    System.out.println("Sucessfully Sent mail to All Users");
  }

  public void postMail( String recipients[ ], String subject,
                            String message , String from) throws MessagingException
  {
    boolean debug = false;

     //Set the host smtp address
     Properties props = new Properties();
     props.put("mail.smtp.host", SMTP_HOST_NAME);
     props.put("mail.smtp.auth", "true");
    
        SMTPAuthenticator auth = new SMTPAuthenticator();
    Session session = Session.getDefaultInstance(props, auth);

    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.length];
    for (int i = 0; i < recipients.length; i++)
    {
        addressTo[i] = new InternetAddress(recipients[i]);
    }
    msg.setRecipients(Message.RecipientType.TO, addressTo);

    // Setting the Subject and Content Type
    msg.setSubject(subject);
    msg.setContent(message, "text/plain");
    System.out.println("before transport " +from);
    Transport.send(msg);
    System.out.println("after transport .. " +from);
 }


/**
* SimpleAuthenticator is used to do simple authentication
* when the SMTP server requires it.
*/
private class SMTPAuthenticator extends javax.mail.Authenticator
{
	

    public PasswordAuthentication getPasswordAuthentication()
    {
    	System.out.println("here in smtpauthenticator");

        String username = SMTP_AUTH_USER;
        String password = SMTP_AUTH_PWD;
        return new PasswordAuthentication(username, password);
    }
}

}

Im getting exception in return new PasswordAuthentication(username, password)


Can anybody help on this.......please

below is my exception

Exception in thread "main" javax.mail.AuthenticationFailedException: 250-tx.technoinfo.in Hello [192.168.105.82]
250-SIZE 10485760
250-PIPELINING
250-DSN
250-ENHANCEDSTATUSCODES
250-X-ANONYMOUSTLS
250-AUTH NTLM
250-X-EXPS NTLM
250-8BITMIME
250-BINARYMIME
250-CHUNKING
250 XEXCH50

	at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:648)
	at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:583)
	at javax.mail.Service.connect(Service.java:313)
	at javax.mail.Service.connect(Service.java:172)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.