Last active
October 18, 2021 13:26
-
-
Save marcustw/c780dc5199d2e7a307b15523cba69927 to your computer and use it in GitHub Desktop.
cloud-function
This file contains hidden or 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 region = "asia-east1"; | |
const emailSubject = "Welcome to WaterTop"; | |
const emailTemplate = `<p>Dear Student,</p> <br/> | |
<p>Welcome to School of WaterTop! Thank you for | |
choosing WaterTop as one of your choices and | |
we are pleased to have you here.</p> <br /> | |
<br/> | |
<p>Best Regards,</p> | |
<p>WaterTop</p> | |
`; | |
/** | |
Export sendNoReplyEmail as a HTTP function. | |
*/ | |
exports.sendNoreplyEmail = functions | |
.region(region) | |
.firestore.document("students/{docId}") | |
.onCreate((snapshot) => { | |
// obtain email from student | |
const student = snapshot.data(); | |
if (student) { | |
const destination = student.email; | |
const mailOptions = { | |
from: `${noreplyName} <${noreplyEmail}>`, | |
to: destination, | |
subject: emailSubject, | |
html: emailTemplate, // email content in HTML | |
}; | |
transporter.sendMail(mailOptions, (err, info) => { | |
if (err) { | |
console.log(err.toString()); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment