Nodejs Nodemailer:Sendgrid SMTP用户名&使用现有代码错误的API密钥密码:550 [英] Nodejs Nodemailer : Sendgrid SMTP username & password to API key using existing code error : 550
问题描述
当前,我使用nodejs库('nodemailer')使用sendgrid
TransporterOption:
Currently im using sendgrid using nodejs library "('nodemailer')" TransporterOption:
config:
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);
}
正常工作没有问题。
从用户名迁移/ password在传递api_key作为响应时收到API错误
的错误,即邮件命令失败:550个未经身份验证的发件人
Working FINE with no issues.
migrating from username/password to API key when passing api_key in response getting this error "Mail command failed: 550 Unauthenticated senders not allowed"
选项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 :: $的缺少凭据b $ b普通,名称:错误,堆栈:错误:缺少
的凭据普通 \n
"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
}
},
错误: {消息:邮件命令失败:550个未经身份验证的发件人
不允许 ;, name: Error, stack: Error:邮件命令失败:550
不允许未经身份验证的发件人 n
Error : "{"message":"Mail command failed: 550 Unauthenticated senders not allowed","name":"Error","stack":"Error: Mail command failed: 550 Unauthenticated 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
}
},
错误: {消息:邮件命令失败:550未经身份验证的发件人
不允许,名称:错误,堆栈:错误:邮件命令失败:550
不允许未经身份验证的发件人\n
Error : "{"message":"Mail command failed: 550 Unauthenticated senders not allowed","name":"Error","stack":"Error: Mail command failed: 550 Unauthenticated senders not allowed\n"
推荐答案
我也需要从Sendgrid的基本身份验证迁移到API密钥。
我试图通过以下方式使用API密钥,并且可能可以工作,但不知道我们是否仍通过这种方式使用基本身份验证,很快由于强制性
2FA而失败。
让我知道我们在这里做的是否正确。
I also needed to migrate from basic authentication to API keys for Sendgrid.
I tried to use the API keys in the following way and probably works but do not know if we are still using basic authentication by this way which will soon fail due to compulsory
2FA.
Let me know if what we are doing here is correct.
// 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
< a href = https://sendgrid.com/docs/for-developers/sending-email/authentication/ rel = nofollow noreferrer> https://sendgrid.com/docs/for-developers/sending-email/身份验证/
sendgrid reference links:
https://sendgrid.com/docs/for-developers/sending-email/upgrade-your-authentication-method-to-api-keys
https://sendgrid.com/docs/for-developers/sending-email/authentication/
这篇关于Nodejs Nodemailer:Sendgrid SMTP用户名&使用现有代码错误的API密钥密码:550的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!