Invalid login on create user event when working with Cloud Functions for Firebase and node mailer

Viewed 776

I am using Cloud Functions for Firebase and Nodemailer and putting together code to fire welcome email. Following is the code I have:

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

const nodemailer = require('nodemailer');
const gmailEmail = encodeURIComponent(functions.config().gmail.email);
const gmailPassword = encodeURIComponent(functions.config().gmail.password);

const mailTransport = nodemailer.createTransport(
`smtps://${gmailEmail}:${gmailPassword}@smtp.gmail.com`);
const APP_NAME = 'Test';

exports.sendWelcomeEmail = functions.auth.user().onCreate(event => {
    const user = event.data; // The Firebase user.
    const email = user.email; // The email of the user.
    const displayName = user.displayName; // The display name of the user.

    return sendWelcomeEmail(email, displayName);
});


function sendWelcomeEmail(email, displayName) {
    const mailOptions = {
        from: '"Test" <noreply@test.com>',
        to: email
    };

    // The user subscribed to the newsletter.
    mailOptions.subject = `Welcome to hell!`;
    mailOptions.text = `Hey I hope you will enjoy our service.`;
    return mailTransport.sendMail(mailOptions).then(() => {
        console.log('New welcome email sent to:', email);
    });
}
  • I do have Allow Less secure Apps turned on
  • I do see my gmail address and password in the config. I have verified this by typing firebase functions:config:get in the command line

I am getting the following error Invalid Login even when credentials are correct

1 Answers
Related