const functions = require('firebase-functions');
var nodemailer = require('nodemailer');
// const express=require('express');
var transporter=nodemailer.createTransport('smtps://[email protected]:[email protected]');
exports.sendMail=functions.https.onRequest((req,res)=>{
var mailOptions={
to: '[email protected]',
subject: 'Test Mail',
html: 'Testing with Node.js'
}
transporter.sendMail(mailOptions,function(err,response){
if(err){
res.send('Mail not sent');
}
else{
res.send('Mail sent');
}
});
});
I am sending mail from my Firebase app. I use Firebase cloud functions for sending the mail as per the question I asked in Sending email using Firebase web app. The above code is my index.js file.
And this is my package.json file
{
"name": "functions",
"description": "Cloud Functions for Firebase",
"scripts": {
"serve": "firebase serve --only functions",
"shell": "firebase experimental:functions:shell",
"start": "npm run shell",
"deploy": "firebase deploy --only functions",
"logs": "firebase functions:log"
},
"dependencies": {
"firebase-admin": "~5.4.2",
"firebase-functions": "^0.7.1",
"sendgrid": "^5.2.3"
},
"private": true
}
But while deploy the code I get an error. Did you list all required modules in the package.json dependencies? What is this error. How to solve it?