gpt4 book ai didi

node.js - 如何从azure云中的nodejs应用程序发送gmail?

转载 作者:行者123 更新时间:2023-12-03 01:40:43 25 4
gpt4 key购买 nike

使用nodemailer,我能够在本地发送邮件。但在 azure 中我无法发送邮件。我在下面给出了我的代码:

    var smtpTransport = nodemailer.createTransport({
service: "gmail",
auth: {
user: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ef979797af88828e8683c18c8082" rel="noreferrer noopener nofollow">[email protected]</a>',
pass: 'xx'
}
});

mailOptions={
from: '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ceb6b6b68ea9a3afa7a2e0ada1a3" rel="noreferrer noopener nofollow">[email protected]</a>',
to : '<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="a9d1d1d1d1e9cec4c8c0c587cac6c4" rel="noreferrer noopener nofollow">[email protected]</a>',
subject : "Please confirm your Email account",
text: 'Hello world?',
html : "Hello,<br> Please Click on the link to verify your email.<br>Click here to verify"
}
console.log(mailOptions);
smtpTransport.sendMail(mailOptions, function(error, response){
if(error){
console.log(error);
res.end("error");
}else{
console.log("Message sent: " + response.message);
res.end("sent");
}
});

这是正确的方法还是我需要修改某些内容才能使其在 azure 云中工作?你能帮我解决这个问题吗?

我在云中收到以下错误:

   { Error: Invalid login: 534-5.7.14 <https://accounts.google.com/signin /continue?sarp=1&scc=1&plt=AKgnsbv9
534-5.7.14
534-5.7.14 i4B-3uDchhvH5tTH8yHwwR9VlDCAASd24gT6pvUq0R5bAUeoId> Please log

in via
534-5.7.14 your web browser and then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754

l185sm50619884pfl.54 - gsmtp
at SMTPConnection._formatError (/home/Cello1/studio/node_modules
/nodemailer/lib/smtp-connection/index.js:605:19)
at SMTPConnection._actionAUTHComplete (/home/Cello1/studio/node_modules
/nodemailer/lib/smtp-connection/index.js:1340:34)
at SMTPConnection._responseActions.push.str (/home/Cello1/studio
/node_modules/nodemailer/lib/smtp-connection/index.js:378:26)
at SMTPConnection._processResponse (/home/Cello1/studio/node_modules
/nodemailer/lib/smtp-connection/index.js:764:20)
at SMTPConnection._onData (/home/Cello1/studio/node_modules/nodemailer
/lib/smtp-connection/index.js:570:14)
at TLSSocket._socket.on.chunk (/home/Cello1/studio
/node_modules/nodemailer/lib/smtp-connection/index.js:710:55)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
code: 'EAUTH',

最佳答案

根据您的描述,我不知道您使用的Azure服务是什么。

如果您使用的是 Azure 应用服务(包括 Web 应用、函数等),则有 some restrictions您需要知道,这可能会导致您的问题。

如果您使用的是 Azure VM 或容器,请首先检查您的网络出站配置。好像有a similar issue在 GitHub 中,它可能会帮助您尝试使用 oauth 进行身份验证以发送 gmail。

通常,推荐的发送邮件方式是使用 Azure 上的 SendGrid 服务。可以引用官方文档How to Send Email Using SendGrid from Node.js了解如何开始。

关于node.js - 如何从azure云中的nodejs应用程序发送gmail?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53928402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com