javax.mail.AuthenticationFailedException: 535 5.7.3 身份验证不成功

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33243450/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:30:46  来源:igfitidea点击:

javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful

javaemail

提问by Mukesh Kumar

I am sending e email using an SMTP error . I am getting Authentication unsuccessful. The username and password are correct. Am I doing something wrong.

我正在使用 SMTP 错误发送电子邮件。我的身份验证失败。用户名和密码正确。难道我做错了什么。

The error logs are

错误日志是

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class EmailSender{

    public static void main(String args[]) {
        String to = "[email protected]";            // sender email
        String from = "[email protected]";       // receiver email
        String host = "dkdkdd.xxx.com";                   // mail server host

        String login="dkkdkd";
        String pass="dkkdkd";
       Properties properties = System.getProperties();
        properties.setProperty("mail.smtp.host", host);
        properties.setProperty("mail.smtp.user", login);
        properties.setProperty("mail.smtp.password", pass);
        properties.setProperty("mail.smtps.ssl.enable", "true");
       // properties.setProperty("mail.smtp.auth", "true"); 

        Session session = Session.getDefaultInstance(properties); // default session

        try {
            MimeMessage message = new MimeMessage(session);        // email message
            message.setFrom(new InternetAddress(from));                    // setting header fields
            message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
            message.setSubject("Test Mail from Java Program"); // subject line

            // actual mail body
            message.setText("You can send mail from Java program by using");

            // Send message
            Transport transport = session.getTransport("smtp");
            transport.connect(host, login, pass);
            Transport.send(message);
            System.out.println("Email Sent successfully....");
        } catch (MessagingException mex) {
            mex.printStackTrace();
        }
    }

}

The error is

错误是

DEBUG SMTP: AUTH NTLM failed Exception in thread "main" javax.mail.AuthenticationFailedException: 535 5.7.3 Authentication unsuccessful

调试 SMTP:AUTH NTLM 失败线程“main”中的异常 javax.mail.AuthenticationFailedException:535 5.7.3 身份验证不成功

at com.sun.mail.smtp.SMTPTransport$Authenticator.authenticate(SMTPTransport.java:826)
at com.sun.mail.smtp.SMTPTransport.authenticate(SMTPTransport.java:761)
at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:685)
at javax.mail.Service.connect(Service.java:317)
at javax.mail.Service.connect(Service.java:176)
at javax.mail.Service.connect(Service.java:125)
at javax.mail.Transport.send0(Transport.java:194)
at javax.mail.Transport.send(Transport.java:124)

回答by ΦXoc? ? Пepeúpa ツ

It looks like the problem in how you do the session part...

看起来你如何做会话部分的问题......

try doing this:

尝试这样做:

private Properties emailPorperties;

... ...

……

    emailPorperties = new Properties();
    emailPorperties.put("mail.smtp.host", "your host");
    emailPorperties.put("mail.smtp.socketFactory.port", "your port");
    emailPorperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
    emailPorperties.put("mail.smtp.auth", "true");
    emailPorperties.put("mail.smtp.port", "your port");
    emailPorperties.put("mail.smtp.ssl.enable", "true");
    emailSession = Session.getInstance(emailPorperties, new Authenticator() {

            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                System.out.println("Authenticating");
                return new PasswordAuthentication(USER_NAME, PASSWORD);
            }

        });

回答by Mannekenpix

Had the same issue. It's an MS Exchange error that you receive. You are probably not allowed to use your email to send an email via a relay. The administrator of the Exchange server needs to give the rights to do that.

有同样的问题。这是您收到的 MS Exchange 错误。您可能不被允许使用您的电子邮件通过中继发送电子邮件。Exchange 服务器的管理员需要授予执行此操作的权限。

It has nothing to do with a configuration problem on the Java side.

它与Java端的配置问题无关。

回答by idiagne

Hello i've got the same issue in the past. So to solve it i have to connect on the webmail of my outlook or exchage and i noticed that these connexions were stopped by the server so inside i confirm that these transactions was mine. So u have also to do it usually every 2 month in my case.

您好,我过去也遇到过同样的问题。所以为了解决这个问题,我必须连接我的 Outlook 或交易所的网络邮件,我注意到这些连接被服务器停止,所以我在里面确认这些交易是我的。因此,在我的情况下,您还必须通常每 2 个月进行一次。

The problem is not in the code. The problem occurs because something is wrong with the configuration of the mailboxes I believe.

问题不在代码中。出现问题是因为我认为邮箱的配置有问题。

回答by Krishna

Same issue resolve by enabling IMAP of the sender email account in Exchange Control Panel (ECP) of outlook mail admin.

通过在 Outlook 邮件管理员的 Exchange 控制面板 (ECP) 中启用发件人电子邮件帐户的 IMAP 解决了相同的问题。