我一直试图将我的Mailjet事务处理模板集成到我的“新联系人”路线中,以便在新联系人在我的网站表单上注册以发送时事通讯时发送电子邮件,但是在提交表单时它仍然显示错误401。没有收到电子邮件,显然没有发送邮件...
如果在此之前有人遇到过这个问题,我将不胜感激。
非常感谢您的回报!
这是我的“联系”路线GET和POST:
router.get('/contact', function(req, res, next) {
mongoose.model('contacts').find(
function(err, contact){
res.render('contact', {contact, isLoggedIn});
});
});
router.post('/contact', function(req, res, next) {
var newContact = new contactModel({
contactName: req.body.contactName,
contactEmail: req.body.contactEmail,
contactPhone: req.body.contactPhone,
contactMessage: req.body.contactMessage,
contactNews: req.body.contactNews
});
newContact.save(
function(error, contact){
mongoose.model('contacts').find(
function(err, contact){
req.session.contact = contact;
res.render('index', {contact, isLoggedIn});
})
})
contactModel.find(
{
_id: req.body._id
},
function(err, contact) {
const request = mailjet
.post("send", {'version': 'v3.1'})
.request({
"Messages":[
{
"From": {
"Email": "xxxx@hotmail.fr",
"Name": "xx"
},
"To": [
{
"Email":req.body.contactEmail,
"Name": req.body.contactName
}
],
"TemplateID": xxxx,
"TemplateLanguage": true,
"Subject": "xxx",
"Variables": {}
}
]
})
request
.then((result) => {
console.log(result.body)
})
.catch((err) => {
console.log(err.statusCode)
})
});
});
module.exports = router;