Reputation: 3458
I am working with the node mailer npm. I have been working off a tutorial on the eduonix node js course and am working through the docs provided on github https://github.com/andris9/Nodemailer.
I am trying to work through the TL;DR Usage Example. However, I cannot find the error that I am receiving from my command line.
error { [Error: Invalid login]
code: 'EAUTH',
response: '535-5.7.8 Username and Password not accepted. Learn more
at\n535 5.7.8 http://support.google.com/mail/bin/answer.py?answer=14257
v3sm2210622igk.1 - gsmtp',
responseCode: 535 }
I am logged into my gmail and yahoo accounts. Here is my code in express. I have
var nodemailer = require('nodemailer')
sendMail:function(req,res,next){
// res.send('email coming next');
var transporter = nodemailer.createTransport({
service:'Gmail',
auth: {
user:'[email protected]',
pass:'password'
}
});
var mailOptions = {
from: 'John Doe <[email protected]>',
to: '[email protected]',
subject:'financing',
text: 'You have a new submission with the following details...Name: '+req.body.name + 'email: '+ req.body.email + 'message: '+req.body.message
html: '<p>You got a new submission with the following details </p><ul><li>Name: '+req.body.name + '</li><li>Email: '+req.body.email + '</li><li>message: ' + req.body.message + "</li></ul>"
};
transporter.sendMail(mailOptions,function(error,info){
if(error){
console.log('error ',error);
res.redirect('/')
} else{
console.log('Message sent: ' +info.response);
res.redirect('/');
}
});
};
In my html here is my form I made sure to add name to each input and I am calling the post method within the form.
<form class="form-horizontal" action="/send" method="post">
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Name</label>
<div class="col-sm-10">
<input type="text" name="name"class="form-control" id="name" placeholder="Name">
</div>
</div>
<div class="form-group">
<label for="inputEmail3" class="col-sm-2 control-label">Email</label>
<div class="col-sm-10">
<input type="email" class="form-control" id="inputEmail3" placeholder="Email">
</div>
</div>
<div class="form-group">
<label for="phoneNumber" class="col-sm-2 control-label">Phone Number</label>
<div class="col-sm-10">
<input type="text" name="phoneNumber"class="form-control" id="inputPassword3" placeholder="PhoneNumber">
</div>
</div>
<div class="form-group">
<label for="message" class="col-sm-2 control-label">Message</label>
<div class="col-sm-10">
<input type="text" name="message"class="form-control" id="message" placeholder="message">
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-default">Submit</button>
</div>
</div>
</form>
Upvotes: 0
Views: 1210
Reputation: 34677
Gmail blocks login from anywhere but their web apps.
The nodemailer docs explain this issue and how to resolve it.
Basically turn on Less secure apps on your account.
Using Gmail
Even though Gmail is the fastest way to get started with sending emails, it is by no means a preferable solution unless you are using OAuth2 authentication. Gmail expects the user to be an actual user not a robot so it runs a lot of heuristics for every login attempt and blocks anything that looks suspicious to defend the user from account hijacking attempts. For example you might run into trouble if your server is in another geographical location – everything works in your dev machine but messages are blocked in production.
Additionally Gmail has came up with the concept of 'less secure' apps which is basically anyone who uses plain password to login to Gmail, so you might end up in a situation where one username can send (support for 'less secure' apps is enabled) but other is blocked (support for 'less secure' apps is disabled).
To prevent having login issues you should either use XOAUTH2 (see details here) or use another provider and preferably a dedicated one like Mailgun or SendGrid or any other. Usually these providers have free plans available that are compareable to the daily sending limits of Gmail. Gmail has a limit of 500 recipients a day (a message with one To and one Cc address counts as two messages since it has two recipients) for @gmail.com addresses and 2000 for Google Apps customers, larger SMTP providers usually offer about 200-300 recipients a day for free.
Upvotes: 1