0
votes

I have created a firebase function which sends an email once triggered. The issue is that when I try deploying it, it gives me an error

  • functions: Finished running predeploy script. i functions: ensuring required API cloudfunctions.googleapis.com is enabled... i functions: ensuring required API cloudbuild.googleapis.com is enabled...
  • functions: required API cloudbuild.googleapis.com is enabled
  • functions: required API cloudfunctions.googleapis.com is enabled i functions: preparing functions directory for uploading... i functions: packaged functions (40.62 KB) for uploading
  • functions: functions folder uploaded successfully i functions: creating Node.js 10 function sendMail(us-central1)...

Functions deploy had errors with the following functions: sendMail(us-central1)

To try redeploying those functions, run: firebase deploy --only "functions:sendMail"

To continue deploying other features (such as database), run: firebase deploy --except functions

Error: Functions did not deploy properly.

here is my current code:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
const nodemailer = require('nodemailer');
const cors = require('cors')({origin: true});
admin.initializeApp();

let transporter = nodemailer.createTransport({
    service: 'gmail',
    auth: {
        user: 'yourgmailaccount@gmail.com',
        pass: 'yourgmailaccpassword'
    }
});

exports.sendMail = functions.https.onRequest((req, res) => {
    cors(req, res, () => {
  
    const dest = req.query.dest;

    const mailOptions = {
        from: 'Your Account Name <yourgmailaccount@gmail.com>', 
        to: dest,
        subject: 'I\'M A PICKLE!!!', 
        html: `<p style="font-size: 16px;">Pickle Riiiiiiiiiiiiiiiick!!</p>` 
    };

    return transporter.sendMail(mailOptions, (erro, info) => {
        if(erro){
            return res.send(erro.toString());
        }
        return res.send('Sended');
    });
});    
});

how can I resolve this?

1

1 Answers

0
votes

The cause of this issue can be hard to debug, many users have resolved this by changing their CLI version, others simply require a redeploy.

  • Run the command firebase deploy --only "functions:sendMail"
  • Updating to the latest firebase-tools@latest
  • Downgrading firebase-tools@8.20.0 to the previous major version
  • Other versions can be found here firebase-tools