【问题标题】:Nodemailer / Sendgrid with apikeyNodemailer / Sendgrid 与 apikey
【发布时间】:2016-01-15 12:39:50
【问题描述】:

我正在尝试使用 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
    }
};

它不断返回错误的用户名/密码。

它适用于我的用户名 (api_user) 和密码 (api_key)。

谁能解释我需要做什么?

干杯,迈克

【问题讨论】:

    标签: sendgrid nodemailer


    【解决方案1】:

    好的,我想通了。在这种情况下,您删除 api_user 并使用长键。例如

    var options = {
    auth: {
        api_key: 'SG.xnh-4XqZGH6$HLT-IEOPFG.Wl2rB-CN00-nj3x5NiKno7MpDk8DxTtvgJeZfDGGI' // fake
    }
    

    };

    最好的,迈克

    【讨论】:

    • 我有类似的问题我试过你的建议没有解决我的问题你能看看我的问题我做错了什么吗? :stackoverflow.com/questions/64470449/…
    • 我已通过 SendGrid 验证,这符合 2021 年 3 月要求将您的身份验证方法替换为 API 密钥的要求。谢谢!
    【解决方案2】:

    您可以同时使用 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

    【讨论】:

    • 如果使用 Typescript,你需要使用这个答案而不是接受的答案,因为 SMTPTransport.Options 对象需要这个结构。
    【解决方案3】:

    对于任何对此感到困惑的人:现在首选的方法似乎是安装 nodemailer-sendgrid 包,它允许您设置 apiKey 属性 - 请在此处查看我的答案 https://stackoverflow.com/a/64726992/769726 p>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-11-28
      • 1970-01-01
      • 2013-01-04
      • 2017-12-21
      相关资源
      最近更新 更多