title: 535 5.7.139 Authentication unsuccessful, SmtpClientAuthentication is disabled for the Tenant
body: <p>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.</p>
  
  <pre class="lang-java prettyprint-override"><code>public class Office365TextMsgSend {
  
  Properties properties;
  Session session;
  MimeMessage mimeMessage;
  
  String USERNAME = &quot;xxxx@xxxx.xx&quot;;
  String PASSWORD = &quot;xxxxxxx&quot;;
  String HOSTNAME = &quot;smtp.office365.com&quot;;
  String STARTTLS_PORT = &quot;587&quot;;
  boolean STARTTLS = true;
  boolean AUTH = true;
  String FromAddress=&quot;xxxx@xxxx.xx&quot;;
  
  public static void main(String args[]) throws MessagingException {
      String EmailSubject = &quot;Subject:Text Subject&quot;;
      String EmailBody = &quot;Text Message Body: Hello World&quot;;
      String ToAddress = &quot;xxxxxx@gmail.com&quot;;
      Office365TextMsgSend office365TextMsgSend = new Office365TextMsgSend();
      office365TextMsgSend.sendGmail(EmailSubject, EmailBody, ToAddress);
  }
  
  public void sendGmail(String EmailSubject, String EmailBody, String ToAddress) {
      try {
          properties = new Properties();
          properties.put(&quot;mail.smtp.host&quot;, HOSTNAME);
          // Setting STARTTLS_PORT
          properties.put(&quot;mail.smtp.port&quot;, STARTTLS_PORT);
          // AUTH enabled
          properties.put(&quot;mail.smtp.auth&quot;, AUTH);
          // STARTTLS enabled
          properties.put(&quot;mail.smtp.starttls.enable&quot;, STARTTLS);
          properties.put(&quot;mail.smtp.ssl.protocols&quot;, &quot;TLSv1.2&quot;);
          // 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(&quot;Mail Send Successfully&quot;);
  
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
  
  }
  </code></pre>
  <p>Error:</p>
  <blockquote>
  <p>javax.mail.AuthenticationFailedException: 535 5.7.139 Authentication
  unsuccessful, SmtpClientAuthentication is disabled for the Tenant.
  Visit <a href="https://aka.ms/smtp_auth_disabled" rel="nofollow noreferrer">https://aka.ms/smtp_auth_disabled</a> for more information.
  [MA1PR01CA0169.INDPRD01.PROD.OUTLOOK.COM]</p>
  </blockquote>