Skip to content

Instantly share code, notes, and snippets.

@adityajoshi12
Last active February 26, 2019 14:49
Show Gist options
  • Save adityajoshi12/e994da6136f45fea0412475f0ed10fe0 to your computer and use it in GitHub Desktop.
Save adityajoshi12/e994da6136f45fea0412475f0ed10fe0 to your computer and use it in GitHub Desktop.
const functions = require('firebase-functions');
const admin = require("firebase-admin");
const fs=require('fs');
const nodemailer = require('nodemailer');
admin.initializeApp();
const gmailEmail = "sendermail@gmail.com";
const gmailPassword = "password";
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: gmailEmail,
pass: gmailPassword,
},
});
var htmlmail=fs.readFileSync("welcome.html","utf-8").toString();
exports.sendWelcomeEmail = functions.auth.user().onCreate((user) => {
const recipent_email = user.email;
const mailOptions = {
from: '"sender name" <sendermail@gmail.com>',
to: recipent_email,
subject: 'Welcome to MY APP',
html: htmlmail
};
try {
mailTransport.sendMail(mailOptions);
console.log('mail send');
} catch(error) {
console.error('There was an error while sending the email:', error);
}
return null;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment