-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathemailRequest.js
110 lines (99 loc) · 2.93 KB
/
emailRequest.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
const util = require('./util');
const consts = require('./const');
function sendMagicLinkEmail(req, email, magicLink, roomName, callback) {
let name = consts.appName;
let user = consts.appEmail;
let pass = consts.appEmailPass;
let from = consts.appName;
let to = email;
let subject = "Confirm your email";
let html = `
<table width='100%' border='0'>
<tr>
<td style='color:rgb(80, 80, 80); font-family:Verdana; line-height:1.8em; font-size:14px;'>
Hi,
<br/>
Click the button below to claim <b>${util.getHostUrl(req)}/${roomName}</b>.
The link expires in 30 minutes.
<br/><br/>
<a href="${magicLink}">
<button style="background-color: rgb(71, 190, 185); padding: 16px 18px; border: 0; color: white; cursor: pointer;">Claim my link</button>
</a>
<br/><br/>
or
<br/><br/>
Paste the link below in a browser
<br/>
<a href="${magicLink}">${magicLink}</a>
</td>
</tr>
</table>
`;
let data = {
user: user,
pass: pass,
from: from + "<" + user + ">",
to: to,
subject: subject,
html: html
};
util.sendPostRequest(consts.sendEmailUrl, data)
.then(json => {
if (json.status == 'success') {
callback(true);
} else {
console.log(json.message);
callback(false);
}
}).catch(err => {
console.error(err);
callback(false);
});
}
function sendResetCodeEmail(email, code, callback) {
let name = consts.appName;
let user = consts.appEmail;
let pass = consts.appEmailPass;
let from = consts.appName;
let to = email;
let subject = `${code} is your verification code`;
let html = `
<table width='100%' border='0'>
<tr>
<td style='color:rgb(80, 80, 80); font-family:Verdana; line-height:1.8em; font-size:14px;'>
Hi,
<br/>
Your verification code is<br><br>
<b>${code}</b>
<br/><br/>
Copy and paste the code in shareTXT to change your password.
The code expires in 30 minutes.
</td>
</tr>
</table>
`;
let data = {
user: user,
pass: pass,
from: from + "<" + user + ">",
to: to,
subject: subject,
html: html
};
util.sendPostRequest(consts.sendEmailUrl, data)
.then(json => {
if (json.status == 'success') {
callback(true);
} else {
console.log(json.message);
callback(false);
}
}).catch(err => {
console.error(err);
callback(false);
});
}
module.exports = {
sendMagicLinkEmail,
sendResetCodeEmail
};