节点邮递员未发送的邮件

时间:2019-05-21 12:11:13

标签: node.js mongoose ejs nodemailer

当我们单击相应ID的邮件图标时,我正在尝试发送邮件。但是我无法发送邮件。 首先,我单击图标,它将重定向到另一个ejs文件以发送电子邮件,然后从那里发送电子邮件。这里没有发送邮件,所以任何人都可以帮忙吗? 谢谢

mail.ejs

<form action="/send-email" method="POST">
     <div class="col-md-12">
      <div class="form-group">
        <input type="text" class="form-control" placeholder="To" name="to">
      </div>

       <div class="form-group">
         <input type="text" class="form-control" placeholder="From" name="from" id="from">
     </div>

      <div class="form-group">
       <input type="text" class="form-control" placeholder="Subject" name="subject" id="subject">
      </div>

   <div class="form-group">
  <textarea class="form-control" id="content" rows="4"></textarea>
    </div>
    <button type="submit" class="btn btn-primary" id="">Send</button>
   </div>
</form>

Controller.js

router.get('/donation/mail/:emailid', function (req, res, next) {
  res.render('mail', {email: req.query.emailid});
})

router.post('/send-email', function (req, res) {
  var transport = nodemailer.createTransport(smtpTransport({
    service: "gmail",
    port:425,
      auth: {
          // should be replaced with real sender's account
          user: 'xxxx@gmail.com',
          pass: 'gmailpassword'
      }
    }));

  var mailOptions = {
      // should be replaced with real recipient's account
        from:'xxxxx@gmail.com',
        to :  req.param.email,
        subject : req.body.subject,
        text : req.body.text

  };
  transport.sendMail(mailOptions, function(error, info) {
    if (error) {
        return console.log(error);
    }
    console.log('Message sent: ' + info.response);
});

res.redirect("/donation");
});

我已允许我的Gmail帐户访问不安全的应用程序

0 个答案:

没有答案