I\'ve set up a basic NodeJS server (using the nodemailer module) locally (http://localhost:8080
) just so that I can test whether the server can actually send ou
While the above answers do work, I'd like to point out that you can decrease security from Gmail by the following TWO steps.
STEP #1
Google Account: sign-in attempt blocked If this was you You can switch to an app made by Google such as Gmail to access your account (recommended) or change your settings at https://www.google.com/settings/security/lesssecureapps so that your account is no longer protected by modern security standards.
STEP #2
In addition to enabling Allow less secure apps, you might also need to navigate to https://accounts.google.com/DisplayUnlockCaptcha and click continue.
Adding to xShirase answer just providing screenshots where to enable. Also confirm in security that previous attempt was from you.
Xshirase deserves all upvotes.Iam just showing screenshot.
The answer is in the message from google.
Go to : https://www.google.com/settings/security/lesssecureapps
set the Access for less secure apps setting to Enable
For the second part of the problem, and in response to
I'm actually simply following the steps from the nodemailer github page so there are no errors in my code
I will refer you to the nodemailer github page, and this piece of code :
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'gmail.user@gmail.com',
pass: 'userpass'
}
});
It differs slightly from your code, in the fact that you have : nodemailer.createTransport("SMTP"
.
Remove the SMTP parameter and it works (just tested). Also, why encapsulating it in a http server? the following works :
var nodemailer = require('nodemailer');
var transporter = nodemailer.createTransport({
service: 'Gmail',
auth: {
user: 'xxx',
pass: 'xxx'
}
});
console.log('created');
transporter.sendMail({
from: 'xxx@gmail.com',
to: 'xxx@gmail.com',
subject: 'hello world!',
text: 'hello world!'
});