kerim Erkan
kerim Erkan

Reputation: 171

unable to deploy firebase function for react native

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 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: '[email protected]',
        pass: 'yourgmailaccpassword'
    }
});

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

    const mailOptions = {
        from: 'Your Account Name <[email protected]>', 
        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?

Upvotes: 0

Views: 200

Answers (1)

DIGI Byte
DIGI Byte

Reputation: 4163

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 [email protected] to the previous major version
  • Other versions can be found here firebase-tools

Upvotes: 0

Related Questions