72 lines
1.8 KiB
JavaScript
72 lines
1.8 KiB
JavaScript
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 =
|
|
'<p>Hello. User left you a message on Saburly service using Alexa skill.</p><br/><b>Message : </b><br/><p>' +
|
|
message +
|
|
'</p><br/><p>Name : ' +
|
|
name +
|
|
'</p><br/><p>Email : ' +
|
|
fromEmail +
|
|
'</p><br/><b>Your Saburly team</b>';
|
|
|
|
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);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
};
|