Im trying to send a email using node.js - nodemailer module , my whole code looks like
var http=require("http");
var nodemailer=require("nodemailer");
http.createServer(function(req,res){
res.writeHead(200, {"Content-Type": "text/plain"});
var transporter = nodemailer.createTransport('SMTP',{
service: 'gmail',
auth: {
user: '[email protected]', // my mail
pass: 'mypassword'
}
});
var mailOptions = {
from: 'Fred Foo ✔ <[email protected]>', // sender address
to: '[email protected]', // the same mail = want to send it to myself
subject: 'Hello ✔', // Subject line
text: 'Hello world ✔', // plaintext body
html: '<b>Hello world ✔</b>' // html body
};
transporter.sendMail(mailOptions, function(error, info){
if(error){
return console.log(error);
}
console.log('Message sent: ' + info.response);
});
res.end("hllo");
}).listen(4000)
but when i run it , it throws "login" error , altought my name/pass are correct the whole error looks like this
{ [AuthError: Invalid login - 534-5.7.14 <https://accounts.google.com/ContinueSi
gnIn?sarp=1&scc=1&plt=AKgnsbtWV
534-5.7.14 FHw6FqlXkg3nIQW7AtsO7o0r-4EtD7eTtnrgHeXxeULYqUtHjrnTB9R647mlR7GY9Z4lS
z
534-5.7.14 WuzYYnNwNBjIyrjNzHk-o9sIV_vIsbjgF5HsFPtJl5S0dSf3eyNCX_E8tQ_Z6s4Z1mUe5
i
534-5.7.14 p8Y5YagzdN5RSkjpB1yTu3TfWHSTLisczIZphhLfhlz-v86tAB8MX-4jRqA51hfJYy0ko
F
534-5.7.14 qytMeIbs1kUZEJzPIabmjRi87DIk> Please log in via your web browser and
534-5.7.14 then try again.
534-5.7.14 Learn more at
534 5.7.14 https://support.google.com/mail/answer/78754 cx1sm17733852wib.0 - gs
mtp]
name: 'AuthError',
data: '534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt
=AKgnsbtWV\r\n534-5.7.14 FHw6FqlXkg3nIQW7AtsO7o0r-4EtD7eTtnrgHeXxeULYqUtHjrnTB9R
647mlR7GY9Z4lSz\r\534-5.7.14 WuzYYnNwNBjIyrjNzHk-o9sIV_vIsbjgF5HsFPtJl5S0dSf3ey
NCX_E8tQ_Z6s4Z1mUe5i\r\n534-5.7.14 p8Y5YagzdN5RSkjpB1yTu3TfWHSTLisczIZphhLfhlz-v
86tAB8MX-4jRqA51hfJYy0koF\r\n534-5.7.14 qytMeIbs1kUZEJzPIabmjRi87DIk> Please log
in via your web browser and\r\n534-5.7.14 then try again.\r\n534-5.7.14 Learn
more at\r\n534 5.7.14 https://support.google.com/mail/answer/78754 cx1sm1773385
2wib.0 - gsmtp',
stage: 'auth' }
is there something i have to set in my gmail acc to allow this to send email from that or how can i fix it
To get Gmail working with nodemailer, most times, all you have to do is configure your google account by allowing access to "less secure apps" from the security. With this enabled, you could use your Google email address and password for nodemailer and start sending emails right away.
The outgoing SMTP server, smtp.gmail.com , requires TLS. Use port 465 , or port 587 if your client begins with plain text before issuing the STARTTLS command.
If you have a Gmail account, you could use that account with nodemailer directly. However, there are several downsides for doing so. First, there is a limit on outbound email: 500 per day, and each recipient counts as 1 outbound email.
Try installing nodemailer-smtp-transport and then use it inside your createTransport function.
var smtpTransport = require('nodemailer-smtp-transport');
var transport = nodemailer.createTransport(smtpTransport({
service: 'gmail',
auth: {
user: '[email protected]', // my mail
pass: 'mypassword'
}
}));
And try also while in your google account enabling this: https://www.google.com/settings/security/lesssecureapps
I really think this should be your auth problem
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With