I'm trying to send mails with nodejs and nodemailer, but it doesn't work for me. I have this code:
const config = require('../../config');
const http = require('http');
const nodemailer = require('nodemailer');
module.exports = {
sendMail: function (params) {
return new Promise((resolve, reject) => {
var transporter = nodemailer.createTransport({
//service: 'gmail', //I tried with this too
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: params.fromMail,
pass: params.fromPass
}
});
var mailOptions = {
from: params.fromMail,
to: params.toMailList,
subject: params.subject,
html: params.mailHtmlContent,
};
transporter.sendMail(mailOptions, function(err, info){
if (err) {
reject(err);
} else {
resolve(info.response);
}
});
});
}
};
I'm getting this error:
{ Error: Invalid login: 535-5.7.8 Username and Password not accepted. Learn more at 535 5.7.8 https://support.google.com/mail/?p=BadCredentials p6sm97493129wrx.50 - gsmtp at SMTPConnection._formatError (C:\Users\Carlos\Desktop\Proyectos\nodeServer\node_modules\nodemailer\lib\smtp-connection\index.js:774:19) at SMTPConnection._actionAUTHComplete (C:\Users\Carlos\Desktop\Proyectos\nodeServer\node_modules\nodemailer\lib\smtp-connection\index.js:1509:34) at SMTPConnection._responseActions.push.str (C:\Users\Carlos\Desktop\Proyectos\nodeServer\node_modules\nodemailer\lib\smtp-connection\index.js:547:26) at SMTPConnection._processResponse (C:\Users\Carlos\Desktop\Proyectos\nodeServer\node_modules\nodemailer\lib\smtp-connection\index.js:933:20) at SMTPConnection._onData (C:\Users\Carlos\Desktop\Proyectos\nodeServer\node_modules\nodemailer\lib\smtp-connection\index.js:739:14) at TLSSocket._socket.on.chunk (C:\Users\Carlos\Desktop\Proyectos\nodeServer\node_modules\nodemailer\lib\smtp-connection\index.js:691:47) at TLSSocket.emit (events.js:182:13) at addChunk (_stream_readable.js:283:12) at readableAddChunk (_stream_readable.js:264:11) at TLSSocket.Readable.push (_stream_readable.js:219:10) code: 'EAUTH', response: '535-5.7.8 Username and Password not accepted. Learn more at\n535 5.7.8 https://support.google.com/mail/?p=BadCredentials p6sm97493129wrx.50 - gsmtp', responseCode: 535, command: 'AUTH PLAIN' }
I have changed the correspondant param on my gmail account about "less secure apps". I tried with another non gmail account too. I tried with this:
service: 'gmail',
and this for the connection:
host: 'smtp.gmail.com',
port: 465,
secure: true,
I read all "Similar Questions" here in stackoverflow and I don't know if I need anything else or if I'm doing anything bad. (of course I have revieved the username and password in both accounts and they're ok).
What am Im doing bad?
secure: false? If it still doesn't work, try withsecure: truebutport: 587. - MadWard