Wednesday 26 April 2017

Error: No recipients defined when trying to use nodemailer

I've been trying to setup and use nodemailer on my MEAN app. Here is mail.js ... a route I'm using for my server.js file.

'use strict';
const express = require('express');
const router = express.Router();
const nodemailer = require('nodemailer');
const config = require('./config');
const Message = require('../models/message');

var transporter = nodemailer.createTransport({
  service: 'gmail',
  secure: false,
  port: 25,
  auth: {
    user: config.mailUser,
    pass: config.mailPass
  },
  tls: {
    rejectUnauthorized: false
  }
});

router.post('/contact', function(req, res){
  var mailOptions = new Message({
    from: 'jon.corrin@gmail.com',
    to: config.mailUser,
    subject: 'Hey there',
    text: 'This is the test message'
    //html: req.body.html
  });

  transporter.sendMail(mailOptions, function(error, info){
    if(error){
      return console.log(error);
    }
    return console.log('Message %s sent: %s', info.messageId, info.response);
  });
});

module.exports = router;

I'm using postman to make API calls to the backend but the result is the error stated in the headline. Anyone know why? It seems that recipient is defined.



via Jonathan Corrin

No comments:

Post a Comment