-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmail.js
79 lines (73 loc) · 2.68 KB
/
mail.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
var nodemailer = require('nodemailer');
const fs = require('fs');
class Mail {
constructor() {
console.log("Pass: %s, %s",config.NODEMAIL_PASS, config.NODEMAIL_HOST);
this.smtpTransport = nodemailer.createTransport({
host: config.NODEMAIL_HOST,
port: 587,
secure: false, // true for 465, false for other ports
auth: {
user: config.NODEMAIL_USER, // generated user
pass: config.NODEMAIL_PASS // generated password
}
});
}
async sendMail(to, subject, html) {
var mailOptions={
from: 'play@atheios.org',
to: to,
subject: subject,
html: html
}
if (debugon)
console.log(">>>> DEBUG: ",mailOptions);
let info=await this.smtpTransport.sendMail(mailOptions);
if (debugon) {
console.log(">>>> DEBUG: ", mailOptions);
console.log("Message sent: %s", info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
}
}
async sendMailTemplate(tolist, templatenr) {
var subject;
var html;
var text;
var i;
var error=false;
switch (templatenr) {
case 1:
subject="Bloxxchain: New all time high!";
html= fs.readFileSync(__dirname + '/mail_templates/all_time_high.html', 'utf8');
text= fs.readFileSync(__dirname + '/mail_templates/all_time_high.txt', 'utf8');
break;
case 2:
subject="New round, new chance to get onto the first position";
html= fs.readFileSync(__dirname + '/mail_templates/newperiode.html', 'utf8');
text= fs.readFileSync(__dirname + '/mail_templates/newperiode.txt', 'utf8');
break;
default:
error=true;
}
if (error) {
if (debugon)
console.log(">>>> DEBUG: (fn=sendMailTemplate) Template not defined")
} else {
for (i=0;i<tolist.length;i++) {
var mailOptions = {
from: 'master@bloxxchain.info',
to: tolist[i],
subject: subject,
text: text,
html: html
}
let info = await this.smtpTransport.sendMail(mailOptions);
if (debugon) {
console.log("Message sent to: %s with mailid %s", tolist[i], info.messageId);
// Message sent: <b658f8ca-6296-ccf4-8306-87d57a0b4321@example.com>
}
}
}
}
}
module.exports = Mail;