'nodemailer is causing an error in aws ec2 production evnironment

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

var transporter = nodemailer.createTransport({
            service: 'gmail',
            host: 'smtp.gmail.com',
            port : 465,
            secure: true,
            auth: {
                user: '[email protected]',
                pass: 'password'
            }
        });
 const mailOptions = {
            from: '[email protected]', // 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 not sending email and 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 as well.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source