Guest User

Untitled

a guest
Nov 17th, 2018
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. //Mail
  2. const nodemailer = require('nodemailer')
  3. const postmarkTransport = require('nodemailer-postmark-transport')
  4.  
  5.  
  6. // Google Cloud environment variable used:
  7. // firebase functions:config:set postmark.key="API-KEY-HERE"
  8. const postmarkKey = functions.config().postmark.key
  9. const mailTransport = nodemailer.createTransport(postmarkTransport({
  10. auth: {
  11. apiKey: postmarkKey
  12. }
  13. }))
  14. exports.OnUserCreation = functions.auth.user().onCreate((user) =>
  15. {
  16. console.log("user created: " + user.data.uid);
  17. sendEmail(user);
  18. })
  19.  
  20. function sendEmail(user)
  21. {
  22. // Send welcome email to new users
  23. const mailOptions =
  24. {
  25. from: '"test" <test@test.com>',
  26. to: user.email,
  27. subject: 'Welcome!',
  28. html: 'hello'
  29. }
  30. // Process the sending of this email via nodemailer
  31. return mailTransport.sendMail(mailOptions)
  32. .then(() => console.log('Welcome confirmation email sent'))
  33. .catch((error) => console.error('There was an error while sending the welcome email:', error))
  34. }
  35.  
  36. const mailOptions = {
  37. from: 'test@test.com',
  38. to: user.email,
  39. subject: 'Welcome!',
  40. textBody: 'hello'
  41. }
Add Comment
Please, Sign In to add comment