admin管理员组文章数量:1431406
Im making an Node.js app for my work that should send pdfs in emails through our Entra outlook work domain. Currently I am trying to do so with Oauth2 sonce we use MFA for our accounts and the farthest I have gotten is now receiving Error 536 5.7.8 another step is required in authentication.
What could be the source of this error and how would I bypass it?
So the app worked perfectly when sending emails from my gmail test account with an app password. When I moved to our domain I tried first with normal password which ended up in 536 5.7.8 authentication failure. Same happened when we in out Entra allowed app passwords and tried it with those. I have checked multiple times and tried with several different app passwords out of which none worked even days after generating them. App code
//App password code
const transporter = nodemailer.createTransport({
host: "entradomain",
port: 587,
secure: false,
auth: {
user: "[email protected]", // req.body.sender
pass: "app password" // req.body.pass
}
});
//App password server output
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-PIPELINING
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-SIZE 18874368
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-VRFY
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-ETRN
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-AUTH DIGEST-MD5 PLAIN LOGIN
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-ENHANCEDSTATUSCODES
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-8BITMIME
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-DSN
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250-SMTPUTF8
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] S: 250 CHUNKING
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] SMTP handshake finished
[2024-11-18 15:14:13] DEBUG [r7nmlU27tI] C: AUTH PLAIN
[2024-11-18 15:14:13] DEBUG [mGNxKhx1V0M] S: 535 5.7.8 Error: authentication failed: authentication failure
So I caved and tried to set up Oath2. I registered the app in our Entra using microsoft Graph and msal library for it. That got me a new error that i have been stuck on for the past few days and can no longer find a way around.
//Oauth2 code
const accessToken = await getAccessToken();
const transporter = nodemailer.createTransport({
host: "entradomain",
port: 587,
secure: false,
auth: {
type: 'OAuth2',
user: "[email protected]", // req.body.sender
clientId: "client id",
clientSecret: 'client seecret',
accessToken: accessToken,
},
tls: {
// do not fail on invalid certs
rejectUnauthorized: false
},
logger: true,
debug: true,
});
bellow is my msal config script
//msal config
const msal = require('@azure/msal-node');
const msalConfig = {
auth: {
clientId: 'clientid',
authority:' id',
clientSecret: 'secret',
}
};
const tokenRequest = {
scopes: ['/.default'],
//scopes: ['/.default'],
};
const pca = new msal.ConfidentialClientApplication(msalConfig);
module.exports = { pca, tokenRequest};
bellow is my token getting script
//get token script
//this script retrieves the Refresh token from the mcalConfig.js script
const { pca, tokenRequest } = require('./msalConfig.cjs');
async function getAccessToken() {
try{
const response = await pca.acquireTokenByClientCredential(tokenRequest);
return response.accessToken;
} catch (error) {
console.error('Errorr getting the token is: ', error);
throw error;
}
}
module.exports = getAccessToken;
lastly here is the server response when I attempt to send an email using the Oauth2
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-PIPELINING
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-SIZE 18874368
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-VRFY
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-ETRN
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-AUTH DIGEST-MD5 PLAIN LOGIN
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-ENHANCEDSTATUSCODES
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-8BITMIME
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-DSN
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250-SMTPUTF8
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] S: 250 CHUNKING
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] SMTP handshake finished
[2024-11-18 13:57:27] DEBUG [5zsQd8LUlmw] C: AUTH XOAUTH2
[2024-11-18 13:57:27] ERROR Send Error: Invalid login: 535 5.7.8 Error: authentication failed: another step is needed in authentication
本文标签:
版权声明:本文标题:node.js - Sending emails using Nodemailer throgh Entra outlook domain with Oauth2 after receiving a 536 5.7.8 another step is re 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745573723a2664203.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论