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('myemail@gmail.com');
})
// [END onWrite]
// Sends a welcome email to the given user.
function sendTestEmail(email) {
const mailOptions = {
from: `${APP_NAME} <noreply@example.com>`,
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
.