4

When I try to send email from nodemailer I get an error: EAUTH API I've tried to use both Hotmail and Gmail as my services as I understand from the documentation that if Gmail doesn't work, don't use it. However this does not appear to be the problem.

I want to use this email to enable forgot password in my App

The code:

var smtpTransport = nodemailer.createTransport({
  service: 'Hotmail',
  auth: {
    user: email,
    pass: pass
  }
});

router.post('/forgotpassword', function(req, res){
            async.waterfall([
                function(done) {
                    User.findOne({
                        email: req.body.email
                    }).exec(function(err, user) {
                        if (user) {
                            done(err, user);
                        } else {
                            done('User not found.');
                        }
                    });
                },
                function(user, done) {
      // create the random token
      crypto.randomBytes(20, function(err, buffer) {
        var token = buffer.toString('hex');
        done(err, user, token);
      });
  },
  function(user, token, done) {
    User.findByIdAndUpdate({ _id: user._id }, { reset_password_token: token, reset_password_expires: Date.now() + 86400000 }, { upsert: true, new: true }).exec(function(err, new_user) {
        done(err, token, new_user);
    });
  },
  function(token, user, done) {
    var data = {
        to: user,
        from: email,
        template: 'forgot-password-email',
        subject: 'Password help has arrived!',
        context: {
            url: 'http://localhost:3000/user/reset_password?token=' + token,
            name: req.body.email
        }
    };

    smtpTransport.sendMail(data, function(err) {
        if (!err) {
            return res.json({ message: 'Kindly check your email for further instructions' });
        } else {
            return done(err);
        }
    });
  }
  ], function(err) {
    return res.status(422).json({ message: err });
  });
        });

My email and password are correct.

The error from postman is

{"message":{"code":"EAUTH","command":"API"}}

3 Answers 3

5

i think you should update your code and require one module for sending:

var nodemailer = require('nodemailer');
var smtpTransport = require('nodemailer-smtp-transport');

var smtpTransport = nodemailer.createTransport(smtpTransport({
  service: 'Hotmail',
  auth: {
    user: email,
    pass: pass
  }
}));

As a security precaution, Google may require you to complete an additional step called Unlock Captcha when signing into a new device or application.

You might need to manually allow access to your Google account.

Login to your Google account using a browser, then visit the link below to unlock it: click here

After clicking Allow button, you should see the message:

Account access enabled. Please try signing in to your Google account again from your new device or application.

and allow to less secure apps access: less secure apps

i test it, work for me

Sign up to request clarification or add additional context in comments.

Comments

1

1- to use Hotmail smtp configuration

   var transporter = nodemailer.createTransport({
        host: "smtp-mail.outlook.com", // hostname
       secureConnection: false, // TLS requires secureConnection to be false
       port: 587, // port for secure SMTP
      tls: {
        ciphers:'SSLv3'
      },
     auth: {
        user: '[email protected]',
         pass: 'myPassword'
        }
  });

Or using built-in service

var transport = nodemailer.createTransport("SMTP", {
  service: "hotmail",
  auth: {
    user: "[email protected]",
    pass: "password"
  }
 });

Ps. make sure that your user name and password is correct, and Hotmail not blocking your connection for security issues.

2- you can use service gmail, but you have to allow less secure connection to your Gmail

Comments

1

That error means your password or email is incorrect, Please check once.

also, you can visit the link below to switch less security

linkhttps://myaccount.google.com/u/1/lesssecureapps

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.