【问题标题】:Modern Oauth2 authentication for sending mails using Nodemailer nodejs使用 Nodemailer nodejs 发送邮件的现代 Oauth2 身份验证
【发布时间】:2020-02-07 20:26:50
【问题描述】:

我正在使用nodemailer 在我的 nodejs 应用程序中发送电子邮件。

var payload = { auth: 
               {
                user: smtpuser,
                pass: smtppass
               },
                to : toAddr,
                from  : emailfrom,
                cc : ccAddr,
                subject : subject,
                html    : content,
                attachments: attachments
              };

var transporter = nodemailer.createTransport(
                   { host: payload.host || 'smtp.office365.com', // Office 365 server
                     port: payload.port || 587,     // secure SMTP
                     secure:payload.secure || false, // false for TLS - as a boolean not string - but the default is false so just remove this completely
                     auth: payload.auth,
                     debug: true,
                     tls: payload.tls || {ciphers: 'SSLv3'}
                   });

transporter.sendMail(payload, function (error, info) {
                if (error) {
                    return console.log(error);
                }
                updateMessage(updatedMsg);
            });

我开始收到此错误:

错误:无效登录:535 5.7.3 身份验证不成功[SN4PR0601CA0002.namprd06.prod.outlook.com]

我的团队现在似乎禁用了基本身份验证。

我需要实现现代身份验证 (Oauth2) 才能使用 Outlook id 通过nodemailer 发送邮件。

有人对此有任何想法吗? 这需要哪些配置(代码)更改?

【问题讨论】:

    标签: node.js oauth-2.0 nodemailer exchange-basicauth


    【解决方案1】:

    我建议您使用 Microsoft Graph 发送电子邮件。有一个易于使用的 REST API 与 OAuth 配合得很好。

    请在下面找到一些链接,以帮助您快速构建它。

    https://docs.microsoft.com/en-us/graph/api/user-sendmail?view=graph-rest-1.0&tabs=http https://docs.microsoft.com/en-us/graph/auth/auth-concepts?view=graph-rest-1.0 https://docs.microsoft.com/en-us/graph/tutorials/node?view=graph-rest-1.0

    【讨论】:

    • 感谢您的回复。我已经用Microsoft graph 实现了。
    猜你喜欢
    • 2019-02-09
    • 2016-11-17
    • 2022-10-14
    • 2019-06-01
    • 1970-01-01
    • 2017-09-22
    • 2018-02-01
    • 2011-06-18
    • 2015-11-23
    相关资源
    最近更新 更多