Babu R
Babu R

Reputation: 1035

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

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.

Upvotes: 2

Views: 18521

Answers (2)

Alex
Alex

Reputation: 91

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.

Upvotes: 1

Rahul Agrawal
Rahul Agrawal

Reputation: 8971

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);

Upvotes: 4

Related Questions