I m trying to send a test email to my email when anything is written in /emails
but the email never gets sent and the function logs are empty.
exports.sendTestEmail = functions.database.ref('/emails')
.onWrite(event => {
return sendTestEmail('[email protected]');
})
// [END onWrite]
// Sends a welcome email to the given user.
function sendTestEmail(email) {
const mailOptions = {
from: `${APP_NAME} <[email protected]>`,
to: email
};
// The user subscribed to the newsletter.
mailOptions.subject = `Welcome to ${APP_NAME}!`;
mailOptions.text = `Hey there! Welcome to ${APP_NAME}. I hope you will enjoy our service.`;
return mailTransport.sendMail(mailOptions).then(() => {
console.log('New welcome email sent to:', email);
});
}
Edit ***
The above code works. I was trying to trigger the function on emails
while the correct name was email
.
Correct way of sending an email using Firebase Cloud Functions!
exports.sendTestEmail = functions.database.ref('/emails')
.onWrite(event => {
return sendTestEmail('[email protected]');
})
// [END onWrite]
// Sends a welcome email to the given user.
function sendTestEmail(email) {
const mailOptions = {
from: `${APP_NAME} <[email protected]>`,
to: email
};
// The user subscribed to the newsletter.
mailOptions.subject = `Welcome to ${APP_NAME}!`;
mailOptions.text = `Hey there! Welcome to ${APP_NAME}. I hope you will enjoy our service.`;
return mailTransport.sendMail(mailOptions).then(() => {
console.log('New welcome email sent to:', email);
});
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With