Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
Firebase doesn't send emails after deploying + no logs

I implemented the code below and it works perfectly fine when I run it in on local machine with npm start

However, when I deploy it on Firebase, the sendOrderEmail function doesn't work.

I don't even get any logs.

const functions = require("firebase-functions");
const admin = require("firebase-admin");
const {email, password} = require('./config');
const nodemailer = require('nodemailer');
const htmlToText = require('nodemailer-html-to-text').htmlToText;

admin.initializeApp();

const mailTransport = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: email,
        pass: password
    }
});

mailTransport.use("compile", htmlToText());

const APP_NAME = 'the.Travelest';

exports.sendUserEmail = functions.database
    .ref("/lettersRequest/{pushId}")
    .onCreate(request => {
        return sendOrderEmail(request.val().email);
    });

async function sendOrderEmail(email){
        const mailOptions = {
            from: `${APP_NAME}`,
            to: email,
            subject: `Your order from ${APP_NAME}`,
            html: `
                <div>
                    <strong> Hello </strong>
                    World
                </div>
            `
        };
        return await mailTransport.sendMail(mailOptions);
    }

UPDATE After checking the logic, I believe that I've found the issues in another place.

So, the logic is - when I click on SUBMIT in form, I send the data to Firebase Runtime Database. And this action triggers the function above and send the email.

However, the SUBMIT button doesn't trigger the process it should trigger. I don't see even console.log result in the console, when I click on SUBMIT Again, it works locally, when I run nom start

Here is the submit handler:

const handleSubmit = event => {
        event.preventDefault();

        setErrors(validate(values))
        setIsSubmitting(true)

        try{
            const newRequestRef = database.ref('lettersRequest').push();
            const newRequest = {
                country: values.country,
                travelersAmount: values.travelersAmount,
                introExtro: values.introExtro,
                comments: values.comments,
                email: values.email,
                phone: values.phone
            };
            newRequestRef.set({
                email: values.email,
                request: newRequest
            });
            console.log("no error")
        }catch(e){
            console.log("error")
        }
    }
over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You are not handling the promise returned by set(). Try this:

const handleSubmit = event => {
event.preventDefault();

  setErrors(validate(values))
  setIsSubmitting(true)

  const newRequestRef = database.ref('lettersRequest').push();
  const newRequest = {
    country: values.country,
    travelersAmount: values.travelersAmount,
    introExtro: values.introExtro,
    comments: values.comments,
    email: values.email,
    phone: values.phone
  };
  newRequestRef.set({
    email: values.email,
    request: newRequest
  }).then(() => {
    console.log("Request Added in Database")
  }).catch(e => console.log(e));
}

If it logs 'Request Added in Database' then it has been added successfully and your function should trigger.

Additionally, this can also be done by a Callable Function which means you call the function directly from the client, do all the validation, add the data in database and send the email instead of using database triggers.

over 4 years ago · Santiago Trujillo Denunciar

0

So, the issue was even more trivial than I could expect :D I did deploy to firebase, but I've never did commit and build project... As a result, nothing was updated after each deploy.

Stupid mistake

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda