[尝试通过nodemailer和mailgun发送电子邮件时发生TypeError

问题描述 投票:0回答:1

晚上。

我正在尝试让nodemail和nodemail-mailgun发送电子邮件。 (最终表单提交结果)。

我尝试过搜索Google以及一般的Google,但似乎找不到相同问题的人。

设置:

const nodemailer = require('nodemailer');
const mg = require('nodemailer-mailgun-transport'),
bodyParser = require('body-parser');


const auth = {
  auth: {
    api_key: 'REMOVED FOR SECURITY',
    domain: 'REMOVED FOR SECURITY'
  }
}

  const nodemailerMailgun = nodemailer.createTransport(mg(auth));

路线:

router.post('/contact', function(req, res, next) {

  console.log('Send Mail...');

  nodemailerMailgun.sendMail({
    from: "[email protected]",
    to: '[email protected]', // An array if you have multiple recipients.
    cc:'[email protected]',
    subject: 'Air Safety NW contact form',
    //You can use "html:" to send HTML email content. It's magic!
    html: '<b>From:</b></br>',
    //You can use "text:" to send plain-text content. It's oldschool!
    text: ""
  }, (err, info) => {
    if (err) {
      console.log(`Error: ${err}`);
    }
    else {
      res.send('Successful!')
    }
  });

});

错误:

asnw>错误:TypeError:无法读取未定义的属性'id'

POST / contact--ms--

我已经删除了模板中的所有js变量,希望它们中的一个可能不正确,但是如果我在.sendmail上方重新发送或console.log req.body.variable,它们就可以正常工作。如果有人知道我可以在哪里查找“ id”,那么我可以找出未定义的内容,那么我也许可以继续前进。

nodemailer mailgun
1个回答
0
投票

您不需要nodemailer-mailgun-transport,nodemailer能够单独发送邮件。

© www.soinside.com 2019 - 2024. All rights reserved.