gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 21:58:08 24 4
gpt4 key购买 nike

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

我已经设置了 Node 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) res.sendStatus(200);

2) res.send("已发送");

留下这一行,一切就开始好了

关于node.js - Node js - 发送基本电子邮件时的发送网格问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34788083/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com