From 6fff910cf110a31183651c01b630a8998bae8655 Mon Sep 17 00:00:00 2001 From: Nicolas Garnier Date: Thu, 22 Sep 2016 19:04:37 +0200 Subject: [PATCH] Switched email confirmation sample to ES6 syntax. Change-Id: I16d1d75b76f1cd08e23aab9393aa2be4d848cc60 --- email-confirmation/functions/index.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/email-confirmation/functions/index.js b/email-confirmation/functions/index.js index 2d1683b..e249021 100644 --- a/email-confirmation/functions/index.js +++ b/email-confirmation/functions/index.js @@ -15,25 +15,25 @@ */ 'use strict'; -var functions = require('firebase-functions'); -var nodemailer = require('nodemailer'); +const functions = require('firebase-functions'); +const nodemailer = require('nodemailer'); // Configure the email transport using the default SMTP transport and a GMail account. // See: https://nodemailer.com/ // For other types of transports (Amazon SES, Sendgrid...) see https://nodemailer.com/2-0-0-beta/setup-transporter/ // TODO(DEVELOPER): Configure your email transport below. For GMail replace the and placeholders. -var mailTransport = nodemailer.createTransport('smtps://:@smtp.gmail.com'); +const mailTransport = nodemailer.createTransport('smtps://nivco%40google.com:yltysyenducxhfvr@smtp.gmail.com'); // Sends an email confirmation when a user changes his mailing list subscription. -exports.sendEmailConfirmation = functions.database().path('/users/{uid}').on('value', function(event) { - var data = event.data; - var val = data.val(); +exports.sendEmailConfirmation = functions.database().path('/users/{uid}').on('value', event => { + const data = event.data; + const val = data.val(); if (!data.changed('subscribedToMailingList')) { return; } - var mailOptions = { + const mailOptions = { from: '"Spammy Corp." ', to: val.email }; @@ -42,15 +42,15 @@ exports.sendEmailConfirmation = functions.database().path('/users/{uid}').on('va if (val.subscribedToMailingList) { mailOptions.subject = 'Thanks for subscribing to our newsletter'; mailOptions.text = 'I will now spam you forever muahahahahah!!!'; - return mailTransport.sendMail(mailOptions).then(function() { - console.log('New subscription confirmation email sent to: ' + val.email); + return mailTransport.sendMail(mailOptions).then(() => { + console.log('New subscription confirmation email sent to:', val.email); }); } // The user unsubscribed to the newsletter. mailOptions.subject = 'Sad to see you go :`('; mailOptions.text = 'I hereby confirm that I will stop the spamming.'; - return mailTransport.sendMail(mailOptions).then(function() { - console.log('New unsubscription confirmation email sent to: ' + val.email); + return mailTransport.sendMail(mailOptions).then(() => { + console.log('New unsubscription confirmation email sent to:', val.email); }); });