Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

447
Visualizações
Nodemailer not working when used with Firebase Functions

I'm trying to send myself an email when a new user account is made in my web app. Here is the current code I'm deploying to Firebase Functions:

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const nodemailer = require("nodemailer");

admin.initializeApp();

require("dotenv").config();

const {
    SENDER_EMAIL,
    SENDER_PASSWORD
} = process.env;

exports.sendEmailNotification = functions.firestore.document("users/{userId}").onCreate(async (snapshot, context) => {
    const data = snapshot.data();

    // create reusable transporter object using the default SMTP transport
    let transporter = nodemailer.createTransport({
        host: "smtp.gmail.com",
        port: 465,
        secure: true,
        auth: {
            user: SENDER_EMAIL,
            pass: SENDER_PASSWORD,
        },
    });

    // send mail with defined transport object
    let info = await transporter.sendMail({
        from: `"MY_APP_NAME" <${SENDER_EMAIL}>`,
        to: "MY_PERSONAL_GMAIL_ACCOUNT",
        subject: `A New User Has Joined MY_APP_NAME!`,
        text: `A new user has joined MY_APP_NAME. Name: ${data.name}, email: ${data.email}`
    });
})

Running a similar version on my machine using the node index.js command works no problem. The problem seems to be when it runs on Firebase Functions.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

According to your current code, it seems to be working correctly, as you said, it only works fine in your machine using the node.js. Probably the guide to follow to get the same result is the Nodemailer as a module for Node.js.

Now, if you would like to do it using Cloud Functions for Firebase, I can highly recommend you to follow the Send Email Using Firebase Functions & Nodemailer guide.

Additional guide for Send Email with Firebase functions and Nodemailer.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda