【问题标题】:Node js - send grid issue on sending basic emailNode js - 在发送基本电子邮件时发送网格问题
【发布时间】:2016-04-19 16:33:51
【问题描述】:

Node js - 在发送基本电子邮件时发送网格问题

我已经设置了我的节点 js 服务器,需要设置帮助。

错误“无法设置标题”

这是我的代码:

  var express = require('express');
  var router = express.Router();
  var sendgrid = require('sendgrid')('IHaveAKey');

  router.get('/', function(req, res) {
    res.sendStatus(200);
  });

  router.get('/welcomeEmail/:email/:name', function(req, res) {
    var subject = 'Hello' + req.params.name;

    sendgrid.send({
      to:       'test@hotmail.co.uk',
      from:     'noreply@test.com',
      subject:  'Test',
      text:     'Welcome'
    }, function(err, json) {
      if (err) { return res.send("Error");}    
      return res.send("Sent");
    });

    res.sendStatus(200);
  });

  module.exports = router;

这是我的错误:

【问题讨论】:

    标签: node.js sendgrid


    【解决方案1】:

    您正在尝试从服务器发送响应 2 次:

    1) res.sendStatus(200);

    2) res.send("Sent");

    离开这一行,一切都会好起来的

    【讨论】:

    • 修复了控制台错误。感谢那。但是,发送网格仍然返回错误。我得到的错误是:“提供的授权授权无效、过期或撤销”
    • 您将错误指定为Error "cant set headers"。解决了。​​
    • 我知道收到此错误消息:“提供的授权授权无效、过期或撤销” - 有什么想法吗?
    猜你喜欢
    • 2018-01-14
    • 2012-01-02
    • 1970-01-01
    • 2016-08-12
    • 2013-04-05
    • 2015-10-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多