Node.js Sendgrid v3 mail返回202,但电子邮件不返回';不发送
我正在尝试通过Sendgrid向第一次注册的用户发送电子邮件验证。根据找到的v3_邮件示例,我创建了以下实现:Node.js Sendgrid v3 mail返回202,但电子邮件不返回';不发送,node.js,email,sendgrid,sendgrid-api-v3,Node.js,Email,Sendgrid,Sendgrid Api V3,我正在尝试通过Sendgrid向第一次注册的用户发送电子邮件验证。根据找到的v3_邮件示例,我创建了以下实现: const querystring = require('querystring'); const helper = require('sendgrid').mail; const https = require('https'); const url = "http://<mywebsite.com>/users/reset/passwordLoggedOut?"; l
const querystring = require('querystring');
const helper = require('sendgrid').mail;
const https = require('https');
const url = "http://<mywebsite.com>/users/reset/passwordLoggedOut?";
let sg = require('sendgrid')(process.env.SENDGRID_API_KEY);
const emails = {};
function sendMail(mail){
const request = sg.emptyRequest({
method: 'POST',
path: '/v3/mail/send',
body: mail.toJSON(),
});
sg.API(request, function(error, response) {
console.log(response.statusCode);
console.log(response.body);
console.log(response.headers);
console.log(error);
});
}
emails.sendActivationEmail = function(user){
let qso = {username: user.username, activationCode: user.activationCode};
let qs = querystring.stringify(qso);
let from = new helper.Email('Thomas.Talhelm@chicagobooth.edu');
let to = new helper.Email(user.username);
let subject = 'Welcome to Psych Study \'16';
let content = new helper.Content('text/html', "<p> Thanks for signing up " +
"for our psych study, please <a href=\"http://<mywebsite.com>/users/validate/account?" +
qs + "\">confirm your email</a></p>");
let mail = new helper.Mail(from, subject, to, content);
sendMail(mail);
console.log('Mail Sent!');
}
module.exports = emails;
const querystring=require('querystring');
const helper=require('sendgrid').mail;
常量https=require('https');
常量url=”http:///users/reset/passwordLoggedOut?";
让sg=require('sendgrid')(process.env.sendgrid\u API\u KEY);
const emails={};
函数sendMail(邮件){
const request=sg.emptyRequest({
方法:“POST”,
路径:'/v3/mail/send',
正文:mail.toJSON(),
});
API(请求、函数(错误、响应){
console.log(响应.状态码);
console.log(response.body);
console.log(response.headers);
console.log(错误);
});
}
emails.sendActivationEmail=函数(用户){
让qso={username:user.username,activationCode:user.activationCode};
设qs=querystring.stringify(qso);
let from=新助手。电子邮件('Thomas。Talhelm@chicagobooth.edu');
let to=new helper.Email(user.username);
让主题='欢迎来到心理研究'16';
让content=new helper.content('text/html',“感谢您的注册”+
“对于我们的心理学研究,请”;
let mail=new helper.mail(发件人、主题、收件人、内容);
sendMail(邮件);
log('Mail Sent!');
}
module.exports=电子邮件;
每当我注册一个用户时,这些函数最终都会被正确调用,尽管我收到的状态码是202(已收到响应,电子邮件已排队等待发送),而且电子邮件永远不会被发送。问题有点类似于,但我的活动日志为空,即使我已通过定义良好的环境变量正确输入SendGrid API。我已尝试重新创建API密钥,对该密钥使用了完全权限,但未从API中找到对此行为的解释。此处存在相同的问题。我向SendGrid的技术支持部门报告了这件事,因为它发生在一台几周前工作正常的服务器上。SendGrid API V3的可能副本希望对您有所帮助@NathanWailes你为什么把它标记为重复的,你所指的答案对任何人都没有帮助,也没有任何人接受answer@MahaDev该问题的答案与该问题是否与该问题重复无关。