Error: Invalid login: 535 5.7.3 Authentication unsuccessful [BMXPR01CA0002.INDPRD01.PROD.OUTLOOK.COM]

Shubham 6 Reputation points
2021-02-15T11:09:02.477+00:00

et transporter = nodemailer.createTransport({
// service: 'outlook',
host: 'smtp-mail.outlook.com',
port: 587, // port for secure SMTP
secure: false,
tls: {
ciphers: 'SSLv3'
},
auth: {
type: 'OAuth2',
user: 'user@harsh.com .com',
accessToken: 'EwAoA+l3BAAU0+FyEzrGK6gRIXxWPxCw8ZPo0GUAAddtjPcZsK+18xMS7TUDZJr/zoGX3oauo4Z1cpYjHaUTgz+ZzVOrd/iKd+tGSJbybl745bvdiVFOYxMNGiLSZXyAKhBcyKujhNbteh8Qd1XvNIWG4I0xqf73kOlUZVGMuk7Ab5lmUaK026B+yKuo6RUZH+CnCOUe0zaLuCPW9LlnxHtEY1scr+TXnyKjqwqDrrAzmoyPBRq5Zm6clzBFnS5853dPYo9/Voh2+1bPxt0hhED29uAwHWuxR4ibbPhF+J2wjaB11DcrTOM1a39mNkf1SGxIlyb0VPAaqqQJT2lIc+uhujIZEwBHbOJOvSuygqr67m+G8tvg0fxaL56XUpcDZgAACBppVBQRk3fo+AE8ls26DzmihVuPpnfWt0Fbb3pZZhGNQgKJxUKvEsgrAaUqh/j15ul+4x+iRlP03u76cYwq8OMpcuVF7XVTmFXJtkQioySaCEZu3hXYHjCfc4VdizCUyjQXnW50z0Z9K+7euXzDv3cw3G2KOg0XtA9W06FbJ8lE71xljCJkMAqD6gJo8eAx5SVnuZhROb4KafFA6NLj9PwNMvWHuF9NRro5/WWWCxdWvvTKtWBDqgp0csIcizzZYr1t4rKposIGTKxy6Na9LG7xv7ee54MNHSq6bDMWLLDWqbdsuBiosl1BBnLd+k5WcSwfR+vv/Bm1W42vuARH4ygAEHXU5o8WxGI7g2vnq/tZ/eqYQMmb1q3SXBm3wZYdmBXkFB9M4bejnJCoUFhDp/jFvNNAwzJkzT5agQ1qM/s2UTToYwVg6vQ3x61oSalDGMbJ+vGgAbqW23P9E3fjYG0BUelDJdT8r5Y4XkoVLtTSAC+UJIgY7oDShzuqSqYJ1rqRXiswfUbOk8YXUiTKXiryOW+ByBiMzf2mWTZMOaIAhMDpN1tPXDBxTOS1vQzB7P8oFhYcrTijPIZezYmdCCAF9pJpKUb6KRMPsyYj+ZzzGoXqrBKRy2J0SSU94k/VaojEhr2AiUOoMw1YOa98POd2jKbZbxpXNwIiNVT2AShCVK85Ag=='
}
});

ejs.renderFile(__dirname + "/views/pages/temp.ejs", { data: data }, function (err, data) {  
    if (err) {  
        console.log(err);  
    } else {  
        var mailOptions = {  
            from: body.email,  
            to: body.to,  
            subject: body.subject,  
            text: ``,  
            html: data  
        };  

        transporter.sendMail(mailOptions, function (error, info) {  
            if (error) {  
                console.log(error);  
            } else {  
                console.log('Email sent: ' + info.response);  
            }  
        });  
    };  
})  

I am getting this error with oauth2 as when i am using it without auth2 with ejail and password it is working fine but not working with oauth2

Microsoft Exchange Online Management
Microsoft Exchange Online Management
Microsoft Exchange Online: A Microsoft email and calendaring hosted service.Management: The act or process of organizing, handling, directing or controlling something.
4,491 questions
{count} vote

2 answers

Sort by: Most helpful
  1. Lucas Liu-MSFT 6,171 Reputation points
    2021-02-16T05:17:01.303+00:00

    Hi @Shubham ,
    In order to better solve this issue, I want confirm the following points:
    What is your email account type?
    How did you send the email?
    How did you get the error message?

    If you enable the authenticated client SMTP submission(SMTP AUTH), SMTP AUTH doesn't support modern authentication (Modern Auth), and only uses basic authentication.
    For more information you could refer to: Enable or disable authenticated client SMTP submission (SMTP AUTH) in Exchange Online

    ----------

    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

  2. Pradeep Kumar 0 Reputation points
    2023-09-22T12:38:33.92+00:00

    Error sending email: Error: Invalid login: 535 5.7.3 Authentication unsuccessful [PN2PR01CA0076.INDPRD01.PROD.OUTLOOK.COM 2023-09-22T12:34:03.188Z 08DBBAC9AE78B1D7]

    Where do i am doing wrong ?
    
    
    // Define the function for sending SMTP email with OAuth 2.0 authentication
    const sendEmailWithOAuth2 = async (req, res) =>{
      // Set up Microsoft Identity Platform (MSAL) client
      const msalConfig = {
        auth: {
          clientId: '591a9a4f-3fb0-4f12-987e-ea6120e747f0',
          authority: 'https://login.microsoftonline.com/76151ff0-c1a1-441c-8aeb-ef2333d01ed7',
          clientSecret: 'XXXXXXXXXXXXXXXXXINa8Q~Qc0X~',
        },
      };
    
      const cca = new ConfidentialClientApplication(msalConfig);
    
      // Define the scopes required for sending emails via Outlook
      const scopes = ['https://outlook.office365.com/.default'];
    
      // Acquire a token
      let accessToken;
    
      try {
        const tokenResponse = await cca.acquireTokenByClientCredential({
          scopes,
        });
        accessToken = tokenResponse.accessToken;
        console.log("accessToken-----------------");
        console.log(accessToken);
      } catch (error) {
        console.error('Error acquiring token:', error);
        return;
      }
    
      // Set up the transport
      const transport = nodemailer.createTransport({
        host: 'smtp.office365.com',
        port: 587, // TLS
        secure: false, // Upgrade to TLS
        auth: {
          type: 'OAuth2',
          user: 'support.p2e@yuwaah.org',
          clientId: '-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx0e747f0',
          accessToken
          pass: 'qncgdbqywcjbypsn',
        },
        tls: {
          ciphers: 'SSLv3', // Specify the desired SSL/TLS version (e.g., SSLv3)
        },
      });
    
      // Send an email
      const mailOptions = {
        from: 'support.p2e@yuwaah.org',
        to: 'payertrust@gmail.com',
        subject: 'Test Email',
        text: 'This is a test email sent from Node.js using Outlook SMTP.',
      };
    
      try {
        const info = await transport.sendMail(mailOptions);
        console.log('Email sent:', info.response);
        res.send(info.response);
    
      } catch (error) {
        console.error('Error sending email:', error);
      }
    }
    
    Where do i am doing wrong ?
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.