When trying to send an email from a 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 in line with the nodemailer docs, and the SMTP handshake always finishes successfully, so I know that this is not an issue with the transporter object.