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

251
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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