535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant
Asked Answered
H

2

6

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.

public class Office365TextMsgSend {

Properties properties;
Session session;
MimeMessage mimeMessage;

String USERNAME = "[email protected]";
String PASSWORD = "xxxxxxx";
String HOSTNAME = "smtp.office365.com";
String STARTTLS_PORT = "587";
boolean STARTTLS = true;
boolean AUTH = true;
String FromAddress="[email protected]";

public static void main(String args[]) throws MessagingException {
    String EmailSubject = "Subject:Text Subject";
    String EmailBody = "Text Message Body: Hello World";
    String ToAddress = "[email protected]";
    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();
    }
}

}

Error:

javax.mail.AuthenticationFailedException: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant. Visit https://aka.ms/smtp_auth_disabled for more information. [MA1PR01CA0169.INDPRD01.PROD.OUTLOOK.COM]

Hughey answered 2/2, 2022 at 11:34 Comment(1)
I have the same problem, and "first" answer i get is "disable/enable it on dashboard administrator". But i'm checking if i can use it without administrator change it.Azov
K
5

As the error explicitly states, SMTP authentication is disabled. It even provides you with a very helpful link to https://aka.ms/smtp_auth_disabled. The link explains how to enable SMTP AUTH for the whole organization or only for some mailboxes.

Kurbash answered 2/2, 2022 at 13:31 Comment(8)
It said we need to disable the SMTP AUTH for the organization. Which becomes complex if your organization is very big and this is a huge change at the org network/security level to engage.Kimmie
If not via smtp then what other alternatives there are? I am unable to send emails on emacs mu4e because of this wretched configuration...Thearchy
Outlook Object Model, EWS, Graph. The last two woudl require you to register your app in Azure to be able to request and receive OAuth tokens.Kurbash
@DmitryStreblechenko Thanks for your reply. To the best of my knowledge registering an app is something that is also blocked (I see a "No access" screen when trying to go to Azure active directory) and so outlook is probably the only option? How one would do such thing?Thearchy
Yes, you need to be an admin in your org to be able to register an app. Outlook Object Model would work, but that means you will need to have Outlook installed with a profile configured to access the mailbox on whose behalf you are sending.Kurbash
Please note that it takes some time for the setting to take effect. In my case it worked after 20 minutes.Excerpt
please explain how you did it, i get Switch to an account that has permission Your account ([email protected]) doesn’t have permission to view or manage this page in the Microsoft 365 admin center.Bedchamber
The admin must do it.Kurbash
E
1

AAD security defaults may block this. I had:

Get-TransportConfig | Format-List SmtpClientAuthenticationDisabled
SmtpClientAuthenticationDisabled : False

But still got 535 5.7.139 authentication unsuccessful

It turned out it was Security defaults in AAD that was the problem

Turn off Security Defaults in 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

You may then check:

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
Emersed answered 21/11, 2022 at 22:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.