Reputation: 99
I am trying to trigger an email every time a new user is added to my firestore database. The following code was written by following a Youtube tutorial as I am not well versed in deploying functions. The code below was written in functions/index.js, but triggers an error that I am not sure how to fix: 'Deployment error. Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs'. The full error can be found below the code. Thanks!
const functions = require("firebase-functions");
const nodemailer = require("nodemailer");
const admin = require("firebase-admin");
admin.initializeApp();
require("dotenv").config();
const { SENDER_EMAIL, SENDER_PASSWORD } = process.env;
exports.sendEmailNotification = functions.firestore
.document("submissions/{docId}")
.onCreate((snap, ctx) => {
const data = snap.data();
let authData = nodemailer.createTransport({
host: "smtp.gmail.com",
port: 465,
secure: true,
auth: { user: SENDER_EMAIL, pass: SENDER_PASSWORD },
});
authData
.sendMail({
from: "[email protected]",
to: `${data.email}`,
subject: `Submssion Accepted`,
text: `${data.email}`,
})
.then((res) => console.log("Successfully sent mail"))
.catch((err) => console.log(err));
});
+ functions: Finished running predeploy script.
i firestore: reading indexes from firestore.indexes.json...
i cloud.firestore: checking firestore.rules for compilation errors...
! [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
+ cloud.firestore: rules file firestore.rules compiled successfully
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 firestore: latest version of firestore.rules already up to date, skipping upload...
+ firestore: deployed indexes in firestore.indexes.json successfully
i functions: preparing functions directory for uploading...
i functions: packaged functions (40.2 KB) for uploading
+ functions: functions folder uploaded successfully
+ firestore: released rules firestore.rules to cloud.firestore
i functions: updating Node.js 10 function sendEmailNotification(us-central1)...
! functions[sendEmailNotification(us-central1)]: Deployment error.
Function failed on loading user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs
Upvotes: 0
Views: 218
Reputation: 11
I added "nodemailer" : "^6.4.11" to the dependencies and it now works for me
Upvotes: 1