NodeMailer No Recipients Defined

When I try to send an email from node.js server using nodemailer, I get the following error:

ERROR: Send Error: No recipients defined 

My code is as follows:

client side:

 var mailData = { from: " myemail@gmail.com ", to: " someoneelse@something.com ", subject: "test", text: "test email" }; $.ajax({ type: 'POST', data: mailData, contentType: 'application/json', url: 'http://localhost:8080/sendEmail', success: function(mailData) { console.log('successfully posted to server.'); } }); 

server side:

 var nodemailer = require('nodemailer'); app.post('/sendEmail', function(mailData) { var transporter = nodemailer.createTransport({ service: 'gmail', auth: { user: ' myemail@gmail.com ', pass: 'mypassword' }, }); transporter.sendMail(mailData, function(error, info) { if (error) { console.log(error); return; } console.log('Message sent'); transporter.close(); }); }); 

This is consistent with the nodemailer docs and the SMTP handshake always succeeds, so I know this is not a problem with the transporter object.

+6
source share
1 answer

This error occurs when the value assigned to the to key in the object specified for the sendMail method is empty. As we can see, this means that something is wrong and you are not getting the same data on the server side as you sent on the client.

I also recommend checking if you are accessing a good variable when acting on the server side. POST parameters are probably available in different ways - please check this in your structure documentation.

For example, in HapiJS, I return the POST parameters this way:

 exports.someAction = function (request, reply) { var postParams = request.payload } 
+6
source

All Articles