how to solve com.sun.mail.smtp.SMTPSendFailedException in java ?

16,830

Solution 1

Try this

props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
props.put("mail.debug", "false");
props.put("mail.smtp.port", port);

And while creating session use this authentication code

l_session = Session.getInstance(props,
                new javax.mail.Authenticator() {

                    protected PasswordAuthentication getPasswordAuthentication() {
                        return new PasswordAuthentication(username, password);
                    }
                });

        l_session.setDebug(true);

Solution 2

Our environment is running under WebSphere 7. To support secured smtps, correct variant to turn on SMTPS AUTHorization is:

"mail.smtps.auth=true"

Actually, according to decompiled sources, before authorizing the mail session WebSphere checks if there is a property composed as: "mail."+ transportProtocol + ".auth" set to "true". This helped me to send emails via gmail.

Share:
16,830
Babu R
Author by

Babu R

Updated on July 15, 2022

Comments

  • Babu R
    Babu R almost 2 years

    I am creating a application in which i am sending mail to users.

    But the problem is while i am using Transport.send(msg) method, it displays the following error:

    com.sun.mail.smtp.SMTPSendFailedException: 530-5.5.1 Authentication Required.
    

    I am using the following properties to send mail.

            props.put("mail.transport.protocol", "smtp");
            props.put("mail.host", smtpHostName);
            props.put("mail.user", smtpUser);
            props.put("mail.password", smtpPass);
            props.put("mail.smtp.auth", smtpAuth == 1 ? true : false);
            props.put("mail.port", smtpPort);
            props.put("mail.smtp.starttls.enable", smtpTLS == 1 ? true : false);
    

    Please help me to resolve this problem.