Nodemailer电子邮件发送无效

时间:2017-10-31 07:43:28

标签: meanjs nodemailer

我试图从我的应用程序发送电子邮件。我尝试了下面的代码。有人可以在我错的地方帮助我吗?

当我提交表单时,我没有收到任何错误。但是,我无法在收件人那边收到电子邮件。

谢谢

'use strict';

var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
 // host: 'smtp.gmail.com',
  service: "Gmail",
  port: 587,
  secure: false, // true for 465, false for other ports
  auth: {
    user: 'xyz@gmail.com',
    pass: '**********'
  }
});
/**
 * Module dependencies.
 */
var path = require('path'),
mongoose = require('mongoose'),
Enquire = mongoose.model('Enquire'),
errorHandler = require(path.resolve('./modules/core/server/controllers/errors.server.controller')),
_ = require('lodash');

exports.sendMail = function(req, res) {

  var data = req.body;
  rand=Math.floor((Math.random() * 100) + 54);
  host=req.get('host');
  console.log("send MailData :: " + data)
  var link="http://"+req.get('host')+"/verify?id="+rand;
  var mailOptions={
    from: data.contactEmail,
    to : 'abc@gmail.com',
    subject : "Please confirm your Email account",
    html : "Hello,<br> This is your test email for the Inquiry Form."
  }
  console.log(mailOptions);
  transporter.sendMail(mailOptions, function(error, response){
    if(error){
      console.log(error);
      res.end("error");
    }else{
      console.log("Message sent: " + response.message);
      res.end("sent");
    }
});
      res.json(data);

};

0 个答案:

没有答案