gpt4 book ai didi

node.js - Nodejs Nodemailer : Sendgrid SMTP username & password to API key using existing code error : 550

转载 作者:行者123 更新时间:2023-12-04 15:58:14 24 4
gpt4 key购买 nike

目前我正在使用使用 nodejs 库“('nodemailer')”的sendgrid转运选项:

配置:

 transporterOption: {
host: process.env.SMTP_HOST, // smtp.sendgrid.net
pool: true,
maxConnections: 20,
rateDelta: 1000,
rateLimit: 150,
auth: {
user: process.env.USER_NAME,
pass: process.env.PASSWORD
}
},

发送代码:

const config = require('./config');
const nodeMailer = require('nodemailer');
const htmlToText = require('nodemailer-html-to-text').htmlToText;



const transporter = nodeMailer.createTransport(config.transporterOption);

transporter.use('compile', htmlToText());


try {

let mailOptions = {
headers: { 'X-SMTPAPI': `{"category":["${myid}"]}` },
from: `"myname" <${toemail}>`,
replyTo: `"myname" <${toemail}>`,
to: `"name" <${emailAdr}>`,
subject: mysubject,
text: mytextbody,
html: myhtmlbodymsg

}
} catch (e) {

console.log(e);
}

工作正常,没有问题。

从用户名/密码迁移到 API key 当传递 api_key 以响应收到此错误“邮件命令失败:550 未经身份验证的发件人不允许”

选项 1:

transporterOption: {
host: process.env.SMTP_HOST, // smtp.sendgrid.net
pool: true,
maxConnections: 20,
rateDelta: 1000,
rateLimit: 150,
auth: {
api_key: process.env.SENDGRID_API_KEY // fakeKEY.kashdkjhjkdhsakjdhksajhd
}
},

"err":{"message":"Missing credentials for"PLAIN"","name":"Error","stack":"Error: Missing credentials for"PLAIN"\n

选项 2:

transporterOption: {
host: process.env.SMTP_HOST, // smtp.sendgrid.net
pool: true,
maxConnections: 20,
rateDelta: 1000,
rateLimit: 150,
auth: {
Username: process.env.USER_NAME, //’apikey’
Password: process.env.SENDGRID_API_KEY // fakekeyssssjhkjsahdkjsahdkjhsa
}
},

Error : “{"message":"Mail command failed: 550 Unauthenticated sendersnot allowed","name":"Error","stack":"Error: Mail command failed: 550Unauthenticated senders not allowed\n”

选项 3:

transporterOption: {
host: process.env.SMTP_HOST, // smtp.sendgrid.net
pool: true,
maxConnections: 20,
rateDelta: 1000,
rateLimit: 150,
auth: {
api_user: 'apikey',
api_key: process.env.SENDGRID_API_KEY // fakekeyssssjhkjsahdkjsahdkjhsa
}
},

Error : “{"message":"Mail command failed: 550 Unauthenticated sendersnot allowed","name":"Error","stack":"Error: Mail command failed: 550Unauthenticated senders not allowed\n”

最佳答案

我还需要从基本身份验证迁移到 Sendgrid 的 API key 。
我尝试通过以下方式使用 API key ,并且可能有效,但不知道我们是否仍在通过这种方式使用基本身份验证,由于强制,很快就会失败2FA.
让我知道我们在这里所做的是否正确。

// This below auth object is specific to NODEMAILER configuration options
// This is NOT the same for sendgrid native API configuration

// you can try with your keys named Username/Password but mine works with user/pass
auth: {
'user': 'apikey', // <--- keep as is
'pass': 'SG.aslknwefn_RANDOM_FAKE_KEY', // <--- your api key
}

sendgrid引用链接:
https://sendgrid.com/docs/for-developers/sending-email/upgrade-your-authentication-method-to-api-keys
https://sendgrid.com/docs/for-developers/sending-email/authentication/

关于node.js - Nodejs Nodemailer : Sendgrid SMTP username & password to API key using existing code error : 550,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64470449/

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