我收到以下 403 错误,表明我无法发送电子邮件,因为我的发件人未经过验证:
Forbidden (403)\n The from address does not match a verified Sender Identity. Mail cannot be sent until this error is resolved. Visit https://sendgrid.com/docs/for-developers/sending-email/sender-identity/ to see the Sender Identity requirements\n from\n null
SendGrid 支持人员确认我的发件人已通过该电子邮件的验证,并表示这一定是我这边的事情。我在本地运行一个 Express js 应用程序,或多或少直接从他们的文档复制了代码。有人有什么建议吗?
const client = require('@sendgrid/mail');
require('dotenv').config();
console.log(process.env.SENDGRID_API_KEY);
client.setApiKey(process.env.SENDGRID_API_KEY);
module.exports.send = async () => {
await client.send({
from: '[email protected]',
to: '[email protected]',
subject: 'Test Email',
text: 'Testing the email body',
});
};
console.log
正确输出存储在我的.env
中的api密钥,如下(当然实际密钥已更改):
SENDGRID_API_KEY = "SG.the_rest_of_my_key"
这意味着“发件人”地址与经过验证的发件人身份不匹配。您必须从 senddrid 上经过验证的列表中的电子邮件地址添加。
请点击以下链接了解有关错误代码的更多详细信息。
https://docs.sendgrid.com/for-developers/sending-email/smtp-errors-and-troubleshooting