-
Notifications
You must be signed in to change notification settings - Fork 30
/
sendemail.js
59 lines (46 loc) · 1.22 KB
/
sendemail.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
var fs = require("fs");
var ejs = require('ejs');
var path = require('path');
var nodemailer = require('nodemailer');
var smtpOptions = {
host: process.env.MAIL_SERVER,
port: 587,
secure: false,
auth: {
user: process.env.MAIL_USER,
pass: process.env.MAIL_PASSWORD
}
}
var lostPasswordTxtTemplate;
var lostPasswordHTMLTemplate;
fs.readFile(
path.join(__dirname, 'views', 'email', 'resetPasswordText.ejs'),
"utf-8",
function(err, file){
lostPasswordTxtTemplate = file;
});
fs.readFile(
path.join(__dirname, 'views', 'email', 'resetPasswordHTML.ejs'),
"utf-8",
function(err, file){
lostPasswordHTMLTemplate = file;
});
var transporter = nodemailer.createTransport(smtpOptions);
var Mailer = function() {
};
Mailer.prototype.send = function send(to, from, subject, text, html){
var message = {
to: to,
from: from,
subject: subject,
text: text,
html: html
};
transporter.sendMail(message);
}
Mailer.prototype.buildLostPasswordBody = function buildLostBody(uuid, userid){
var body = ejs.render(lostPasswordTxtTemplate, {uuid: uuid, username: userid});
var htmlBody = ejs.render(lostPasswordHTMLTemplate, {uuid: uuid, username: userid});
return {text: body, html: htmlBody };
}
module.exports = Mailer;