5

I am sending emails using nodemailer using node.js and i have this configuration to send emails

var transporter = nodemailer.createTransport({
            service: 'gmail',
            host: 'smtp.gmail.com',
            auth: {
                user: 'myemail@gmail.com',
                pass: 'password'
            }
        });
 const mailOptions = {
            from: 'myemail@gmail.com', // sender address
            to: user.company_email, // list of receivers
            subject: 'EnStream New Account Signup Password', // Subject line
            html: `<p style="font-size : 15px;">Please sing in to your en-stream account here <a href="http://demo.en-stream.com/auth/login">http://demo.en-stream.com/auth/login</a> with this password : ${userPassword}</p>`// plain text body
        };

It's sending emails on local environment correctly but in production environment on Aws Ec2 it is throwing this error

code: "EAUTH"
command: "AUTH PLAIN"
response: "534-5.7.14 <https://accounts.google.com/signin/continue?sarp=1&scc=1&plt=AKgnsbua↵534-5.7.14 qup7zOOL4GtmYEf1HEHBASSSBgbuMNJRQqK2v3X9mcxDRX1SrXU2Y_LSqZm7Y7yJvH2PwL↵534-5.7.14 JZW6iSXxsRhBdntFAAamrvitpdKS_YJiE-pEnXWakITAz1PAzwDMxjJPKntQrLl2Qx-xA1↵534-5.7.14 zZ4aTvKvYOAk85YHwABnnd0wHU2HkUeHPoDYqgXUWgSA_8Rrn4xkIsUN> Please log↵534-5.7.14 in via your web browser and then try again.↵534-5.7.14  Learn more at↵534 5.7.14  https://support.google.com/mail/answer/78754 a11sm34494120wrx.5 - gsmtp"
responseCode: 534

I allowed outbound port 465 in my ec2 instance security group like this

enter image description here

What's the real issue in this?

Fahad Subzwari
  • 2,109
  • 3
  • 24
  • 52
  • Have you checked error troubleshooting [steps](https://support.google.com/mail/answer/7126229?visit_id=636911515684785996-1968142063&rd=2#cantsignin)? – Imran Apr 18 '19 at 02:39
  • Does this help? https://serverfault.com/questions/635139/how-to-fix-send-mail-authorization-failed-534-5-7-14 – 1565986223 Apr 18 '19 at 16:31
  • No. I have done these steps already and on my local machine it's working fine but on aws it's not working – Fahad Subzwari Apr 19 '19 at 06:10

1 Answers1

8

You may require permission for this from Gmail.

For which you have to enable the Allow access to your Google Account.

Steps:

  1. Go to this link through the same browser from which you are trying to Login.
  2. It will ask "Allow access to your Google Account". Click on "Continue" button.
  3. The message "Account access enabled" will be displayed.

Also, setting for "Less Secure Apps" must be allowed. Go through this link: https://myaccount.google.com/lesssecureapps.

If the issue still persists, check if your server IP is blocked by Gmail.

This should help!

Aress Support
  • 1,315
  • 5
  • 12
  • Please refer to this : https://stackoverflow.com/questions/33493963/nodemailer-is-not-able-send-mail-using-gmail. This may help. – Aress Support Apr 16 '19 at 03:09
  • His problem is different from my problem and i also have different implementation of nodemailer. He did implementation using `xoauth2` but i have implemented using simple `nodemailer` with `http`. – Fahad Subzwari Apr 16 '19 at 05:52
  • My nodemailer worked after allowing access to the google account, thanks ! – Kevin Chan Oct 05 '20 at 18:41