import * as functions from 'firebase-functions' ; import { Email } from '../domain/common/email' ; const nodemailer = require ( 'nodemailer' ) ; const gmailEmail = functions . config ( ) . gmail . email ; const gmailPassword = functions . config ( ) . gmail . password ; const mailTransport = nodemailer . createTransport ( { service : 'gmail' , auth : { user : gmailEmail , pass : gmailPassword } } ) ; /**
 * Send email
 */ const sendEmail = ( email ) => { return new Promise ( ( resolve , reject ) => { const mailOptions = { from : email . from , to : email . to , subject : email . subject , html : email . html } ; mailTransport . sendMail ( mailOptions ) . then ( ( ) => { console . log ( `New subscription confirmation email sent to: ${ email . to }` ) ; resolve ( ) ; } ) . catch ( ( error ) => { console . error ( 'There was an error while sending the email:' , error ) ; reject ( error ) ; } ) ; } ) ; } ; export const emailAPI = { sendEmail } ;