错误:来自电子邮件地址无效-SendGrid



几年来,我一直在使用SendGrid.com处理密码重置电子邮件请求,没有出现任何问题。我没有改变任何东西,在过去的两天里,所有用户都得到了一个">错误:来自电子邮件地址的无效";所有电子邮件请求都有错误。

这发生在所有有效的电子邮件地址上

就我的一生而言,我无法理解为什么这种情况会随机发生。SendGrid的运行似乎没有问题。我正在等待Sendgrid的反馈。

我的设置:

var nodemailer = require('nodemailer');
var sgTransport = require('nodemailer-sendgrid-transport');
app.post('/forgot', usernameToLowerCase, function(req, res, next) {
async.waterfall([
function(done) {
crypto.randomBytes(20, function(err, buf) {
var token = buf.toString('hex');
done(err, token);
});
},
function(token, done) {
User.findOne({ username: req.body.username }, function(err, user) {
if (!user) {
req.flash('error', 'No account with that email address exists.');
return res.redirect('/forgot');
}

user.resetPasswordToken = token;
user.resetPasswordExpires = Date.now() + 3600000; // 1 hour

user.save(function(err) {
done(err, token, user);
});
});
},
function(token, user, done) {


var options = {
auth: {
api_user: '=====',
api_key: '======'
}
}

var client = nodemailer.createTransport(sgTransport(options));

var email = {
from: 'BusinessName',
to: user.username,
subject: 'Reset Your Password',
text:'====='
};

client.sendMail(email, function(err) {
req.flash('success', 'An email was sent to ' + user.username + ' with further instructions.' );
done(err);
});
}
], function(err) {
if (err) return next(err);
res.redirect('/forgot');
});
});

我收到了相同的错误消息"无效的发件人电子邮件地址";在php的SendGrid库中。SendGrid似乎对其关于from字段格式的api进行了一些不兼容的更改。

在我的情况下,from字段不再接受单个电子邮件地址,所以我将其更改为具有单个电子邮件地址的数组,并且它有效。

from: ['some@example.com']

如果没有帮助,请尝试将来自传输包装器的请求与SendGrid文档进行比较https://sendgrid.com/docs/API_Reference/Web_API_v3/index.html.我不确定包装器是如何工作的,但api中from字段的预期格式似乎是这样的:

"from": {
"email": "example@example.com"
}

最新更新