535 5.7.139 身份验证失败,用户被组织的安全默认策略锁定。请联系您的管理员。通过 Office365 smtp 主机和 587 作为端口发送邮件时发生此错误。从管理中心禁用了 MFA,并启用了 smtp 身份验证,并且我正在使用正确的帐户凭据。
import nodemailer from 'nodemailer';
import { MailInterface } from '../models/sendMail';
export default async function main(options: MailInterface) {
try {
const transporter = nodemailer.createTransport({
host: process.env.SMTP_HOST,
// host: "smtp.gmail.com",
port: process.env.SMTP_PORT,
secure: false,
requireTLS: true,
auth: {
user: process.env.SMTP_USERNAME,
pass: process.env.SMTP_PASSWORD,
},
logger: true,
connectionTimeout: 10000, // 10 seconds
greetingTimeout: 10000, // 10 seconds
socketTimeout: 10000 // 10 seconds
});
console.log("SMTP connection established");
// send mail with defined transport object
const info = await transporter.sendMail({
from: process.env.SMTP_USERNAME,
to: options.to,
subject: options.subject,
html: options.html,
headers: { 'x-myheader': 'test header' }
});
console.log("Message sent: %s", info.response);
} catch (error) {
console.error("Error sending email:", error);
throw new Error("Failed to send email");
}
}
现在问题解决了吗?我也遇到了相同的问题,该文档https://learn.microsoft.com/en-us/exchange/troubleshoot/email-delivery/fix-issues-with-printers-scanners-and -lob-applications-that-send-email-using-off#error-authentication-unsuccessful中,没有535 5.7.139 身份验证不成功,用户被组织的安全默认策略锁定。的解决方法