我正在尝试使用apikey在sendgrid中获得一个简单的联系表单并在node.js中运行。目前还不清楚我哪里出错了。
我尝试了以下内容: 1。
var options = {
auth: {
api_user: 'xjh-4XqZGH6$HLT-IEOPFG',
api_key: 'SG.xjh-4XqZGH6$HLT-IEOPFG.Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake obviously, but I would like to show the structure as I am not sure whether this is correct
}
};
和 2。
var options = {
auth: {
api_user: 'xjh-4XqZGH6$HLT-IEOPFG',
api_key: 'Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake obviously, but I would like to show the structure as I am not sure whether this is correct
}
};
和 3。
var options = {
auth: {
api_user: 'apikey',
api_key: 'SG.xnh-4XqZGH6$HLT-IEOPFG.Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake obviously, but I would like to show the structure as I am not sure whether this is correct
}
};
它会继续使用badusername / password返回。
使用我的用户名(api_user)和密码(api_key)可以正常工作。
任何人都可以解释我需要做什么吗?
干杯,迈克
答案 0 :(得分:7)
好的,我明白了。在这种情况下,您删除api_user并使用长键。 E.g。
var options = {
auth: {
api_key: 'SG.xnh-4XqZGH6$HLT-IEOPFG.Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake
}
};
最好,迈克
答案 1 :(得分:0)
对于任何对此绊脚石的人:现在,首选的方法似乎是安装 nodemailer-sendgrid 软件包,该软件包可让您设置apiKey
属性-在此处查看我的答案{ {3}}
答案 2 :(得分:0)
您可以同时使用SMTP和API密钥:
const mailer = nodemailer.createTransport({
host: 'smtp.sendgrid.net',
port: 465,
secure: true,
auth: {
user: 'apikey',
pass: 'SG.XXXX.XXXX',
},
});
官方文档:: https://sendgrid.com/docs/API_Reference/SMTP_API/integrating_with_the_smtp_api.html