Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

245
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!