Last active
February 26, 2019 14:49
-
-
Save adityajoshi12/e994da6136f45fea0412475f0ed10fe0 to your computer and use it in GitHub Desktop.
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 functions = require('firebase-functions'); | |
const admin = require("firebase-admin"); | |
const fs=require('fs'); | |
const nodemailer = require('nodemailer'); | |
admin.initializeApp(); | |
const gmailEmail = "[email protected]"; | |
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" <[email protected]>', | |
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