const nodemailer = require ('nodemailer'); module.exports = { validateEmailFromAlexaResponse: function (email) { //email from alexa response will contain words instead of symbols, like : //at = @ //underscore = _ //dash = - //dot = . //TODO: This list should be longer let transformedEmail = email .replace (/at/gi, '@') .replace (/underscore/gi, '_') .replace (/dash/gi, '-') .replace (/dot/gi, '.'); //Validate here with some email validation regex //return true if email is valid return true; }, sendEmal: function (name, fromEmail, message, toEmail) { return new Promise ((resolve, reject) => { let messageBody = 'Hello. User left you a message on Saburly service using Alexa skill. \r\nMessage : ' + message + '\r\nName : ' + name + '\r\nEmail : ' + fromEmail + '\r\nYour Saburly team'; let messageBodyHTML = '

Hello. User left you a message on Saburly service using Alexa skill.


Message :

' + message + '


Name : ' + name + '


Email : ' + fromEmail + '


Your Saburly team'; let transporter = nodemailer.createTransport ({ host: 'smtp.mail.com', port: 587, secure: false, auth: { user: 'saburly@mail.com', pass: 'KeepSaburly', }, }); var mailOptions = { from: 'saburly@mail.com', replyTo: fromEmail, to: toEmail, subject: 'Message from Saburly service', text: messageBody, html: messageBodyHTML }; transporter.sendMail (mailOptions, (error, info) => { if (error) { reject (error); } else { resolve (info); } }); }); }, };