59 lines
1.4 KiB
JavaScript
59 lines
1.4 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 ' +
|
|
name +
|
|
' left you a message on Saburly service using Alexa. Content of the message : ' +
|
|
message;
|
|
|
|
let transporter = nodemailer.createTransport ({
|
|
host: 'smtp.yandex.com',
|
|
port: 465,
|
|
secure: true,
|
|
auth: {
|
|
user: 'saburly@yandex.com',
|
|
pass: 'WeAreSaburlyTeam',
|
|
},
|
|
});
|
|
|
|
var mailOptions = {
|
|
from: fromEmail,
|
|
replyTo: fromEmail,
|
|
to: toEmail,
|
|
subject: 'Message from Saburly service',
|
|
text: messageBody,
|
|
};
|
|
|
|
transporter.sendMail (mailOptions, (error, info) => {
|
|
if (error) {
|
|
reject (error);
|
|
} else {
|
|
resolve (info);
|
|
}
|
|
});
|
|
});
|
|
},
|
|
};
|