【问题标题】:535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant535 5.7.139 身份验证不成功,为租户禁用 SmtpClientAuthentication
【发布时间】:2022-11-22 07:01:53
【问题描述】:

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

public class Office365TextMsgSend {

Properties properties;
Session session;
MimeMessage mimeMessage;

String USERNAME = "xxxx@xxxx.xx";
String PASSWORD = "xxxxxxx";
String HOSTNAME = "smtp.office365.com";
String STARTTLS_PORT = "587";
boolean STARTTLS = true;
boolean AUTH = true;
String FromAddress="xxxx@xxxx.xx";

public static void main(String args[]) throws MessagingException {
    String EmailSubject = "Subject:Text Subject";
    String EmailBody = "Text Message Body: Hello World";
    String ToAddress = "xxxxxx@gmail.com";
    Office365TextMsgSend office365TextMsgSend = new Office365TextMsgSend();
    office365TextMsgSend.sendGmail(EmailSubject, EmailBody, ToAddress);
}

public void sendGmail(String EmailSubject, String EmailBody, String ToAddress) {
    try {
        properties = new Properties();
        properties.put("mail.smtp.host", HOSTNAME);
        // Setting STARTTLS_PORT
        properties.put("mail.smtp.port", STARTTLS_PORT);
        // AUTH enabled
        properties.put("mail.smtp.auth", AUTH);
        // STARTTLS enabled
        properties.put("mail.smtp.starttls.enable", STARTTLS);
        properties.put("mail.smtp.ssl.protocols", "TLSv1.2");
        // Authenticating
        Authenticator auth = new Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(USERNAME, PASSWORD);
            }
        };

        // creating session
        session = Session.getInstance(properties, auth);

        // create mimemessage
        mimeMessage = new MimeMessage(session);
        
        //from address should exist in the domain
        mimeMessage.setFrom(new InternetAddress(FromAddress));
        mimeMessage.addRecipient(RecipientType.TO, new InternetAddress(ToAddress));
        mimeMessage.setSubject(EmailSubject);

        // setting text message body
        mimeMessage.setText(EmailBody);

        // sending mail
        Transport.send(mimeMessage);
        System.out.println("Mail Send Successfully");

    } catch (Exception e) {
        e.printStackTrace();
    }
}

}

错误:

javax.mail.AuthenticationFailedException:535 5.7.139 身份验证 不成功,为租户禁用 SmtpClientAuthentication。 访问https://aka.ms/smtp_auth_disabled获取更多信息。 [MA1PR01CA0169.INDPRD01.PROD.OUTLOOK.COM]

【问题讨论】:

  • 我有同样的问题,我得到的“第一个”答案是“在仪表板管理员上禁用/启用它”。但是我正在检查是否可以在没有管理员更改的情况下使用它。

标签: java outlook office365 exchange-server


【解决方案1】:

正如错误明确指出的那样,SMTP 身份验证被禁用。它甚至为您提供了一个非常有用的链接https://aka.ms/smtp_auth_disabled。该链接解释了如何为整个组织或仅为某些邮箱启用 SMTP AUTH。

【讨论】:

  • 它说我们需要为组织禁用 SMTP AUTH。如果您的组织非常大,这会变得很复杂,并且这是组织网络/安全级别的巨大变化。
  • 如果不是通过 smtp 那么还有哪些其他选择?由于这种糟糕的配置,我无法在 emacs mu4e 上发送电子邮件...
  • Outlook 对象模型、EWS、图表。最后两个要求您在 Azure 中注册您的应用程序,以便能够请求和接收 OAuth 令牌。
【解决方案2】:

AAD 安全默认值可能会阻止这一点。我有:

Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled
SmtpClientAuthenticationDisabled : False

但是还是得到535 5.7.139认证不成功

原来是 AAD 中的安全默认值才是问题所在

关闭 Azure Active Directory 中的安全默认值

Start by logging into the Azure Active Directory (https://aad.portal.azure.com/). 


Select Azure Active Directory

In left menu click: Azure Active Directory

Select Properties from the menu under Manage

AAD properties

Select Manage security defaults at the very bottom of the properties page

Managing security defaults

Move the slider to No and click Save

save security defaults

然后您可以检查:

Next login to or navigate to the Microsoft 365 Admin Center https://admin.microsoft.com/

Select Settings > Org Settings

Under Services, select Modern Authentication 

Ensure Authentication SMTP is checked

【讨论】:

    猜你喜欢
    • 2022-07-23
    • 2022-06-22
    • 2016-01-19
    • 2019-01-26
    • 1970-01-01
    • 2022-08-05
    • 1970-01-01
    • 2021-11-17
    • 1970-01-01
    相关资源
    最近更新 更多