Created
October 19, 2019 09:24
-
-
Save alexandermckay/0a9fe5b630773ae1599bc40cc6dc1b62 to your computer and use it in GitHub Desktop.
send-mail.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { https } = require('firebase-functions'); | |
const { createTransport } = require('nodemailer'); | |
const sender = '<THE_EMAIL_YOU_JUST_CREATED'; | |
const password = '<THE_PASSWORD_YOU_JUST_CREATED>'; | |
const recipient = '<THE_EMAIL_YOU_ARE_SENDING_TO>'; | |
const transporter = createTransport({ | |
service: 'gmail', | |
auth: { | |
user: sender, | |
pass: password, | |
}, | |
}); | |
const mailOptions = { | |
from: sender, | |
to: recipient, | |
subject: 'Firebase Message', | |
text: 'Working', | |
html: '<h1>Working</h1>', | |
}; | |
const transport = (error, { messageId }) => | |
error ? console.log(error) : console.log(messageId); | |
const handleEmail = (req, res) => { | |
transporter.sendMail(mailOptions, transport); | |
res.send({ status: 200 }); | |
}; | |
module.exports = https.onRequest(handleEmail); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment