节点js - 发送基本电子邮件时发送网格问题

时间:2016-01-14 11:09:39

标签: node.js sendgrid

节点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;

这是我的错误:

enter image description here

1 个答案:

答案 0 :(得分:1)

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

1)res.sendStatus(200);

2)res.send("Sent");

离开这一行,一切都开始好了

相关问题