Skip to content

Instantly share code, notes, and snippets.

@marcustw
Last active October 18, 2021 13:26
Show Gist options
  • Save marcustw/c780dc5199d2e7a307b15523cba69927 to your computer and use it in GitHub Desktop.
Save marcustw/c780dc5199d2e7a307b15523cba69927 to your computer and use it in GitHub Desktop.
cloud-function
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