-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathMailer.js
More file actions
executable file
·160 lines (134 loc) · 5.83 KB
/
Mailer.js
File metadata and controls
executable file
·160 lines (134 loc) · 5.83 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
var nodemailer = require('nodemailer');
//for gmail, opts={service:'gmail', pass:'pass'}
//for ses, opts={service:'ses', id:'aws_id', sekret: 'aws_secret'}
function Mailer(email, opts) {
this._emailID = email;
switch(opts.service) {
case "gmail":
this._smtpTransport = nodemailer.createTransport("SMTP",{
service: "gmail",
auth: {
user: email,
pass: opts.pass
}
});
break;
case "ses":
this._smtpTransport = nodemailer.createTransport("SES", {
AWSAccessKeyID: opts.id,
AWSSecretKey: opts.sekret
});
break;
default:
break;
}
}
Mailer.prototype.sendGenericMail = function(email, subj, msg) {
var mailOptions = {
from: "GT Course Watch Mailer ✔ <"+ this._emailID +">", // sender address
to: email, // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: subj, // Subject line
text: msg // plaintext body
// html: "<b>Hello world ✔</b>" // html body
}
// send mail with defined transport object
this._smtpTransport.sendMail(mailOptions, function(error, response) {
if(error) console.log(error);
// if you don't want to use this transport object anymore, uncomment following line
//_smtpTransport.close(); // shut down the connection pool, no more messages
});
}
Mailer.prototype.sendEmailVerification = function(email, link) {
var htmlBody = "<h1>Click the Link to Complete Verification </h1> <br> " +
'<a href="' + link + '"> Verification Link </a>';
var mailOptions = {
from: "GT Course Watch Mailer ✔ <"+ this._emailID +">", // sender address
to: email, // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: "Email Verification", // Subject line
html: htmlBody
}
this._smtpTransport.sendMail(mailOptions, function(error, response) {
if(error) console.log(error);
});
}
Mailer.prototype.sendPassChangeVerification = function(email, link) {
var htmlBody = "<h1>Click the Link to Change Your Password </h1> <br> " +
'<a href="' + link + '"> Change Password </a>';
var mailOptions = {
from: "GT Course Watch Mailer ✔ <"+ this._emailID +">", // sender address
to: email, // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: "Change Password", // Subject line
html: htmlBody
}
this._smtpTransport.sendMail(mailOptions, function(error, response) {
if(error) console.log(error);
});
}
Mailer.prototype.sendNotificationMail = function(existingRequest, smsRequest) {
var mailOptions = {
from: "GT Course Watch Mailer ✔ <"+ this._emailID +">", // sender address
to: existingRequest.email, // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: "Seat Open for Class: " + existingRequest.crn, // Subject line
text: "Registration Link: " + "https://buzzport.gatech.edu/cp/home/displaylogin", // plaintext body
// html: "<b>Hello world ✔</b>" // html body
}
this._smtpTransport.sendMail(mailOptions, function(error, response) {
if(error) console.log(error);
});
if(smsRequest) {
var smsMailOptions = {
from: "GT Course Watch Mailer ✔ <"+ this._emailID +">", // sender address
to: existingRequest.gatewayedNumber, // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: "Seat Open for Class: " + existingRequest.crn, // Subject line
text: "Registration Link: "+ "https://buzzport.gatech.edu/cp/home/displaylogin", // plaintext body
// html: "<b>Hello world ✔</b>" // html body
}
this._smtpTransport.sendMail(smsMailOptions, function(error, response) {
if(error) console.log(error);
});
}
}
Mailer.prototype.sendAutoRegSuccessMail = function(existingRequest) {
var mailOptions = {
from: "GT Course Watch Mailer ✔ <"+ this._emailID +">", // sender address
to: existingRequest.email, // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: "Registration Success CRN: " + existingRequest.crn, // Subject line
text: "The automatated system was able to successfully register you for your class!", // plaintext body
// html: "<b>Hello world ✔</b>" // html body
}
this._smtpTransport.sendMail(mailOptions, function(error, response) {
if(error) console.log(error);
});
}
Mailer.prototype.sendConfirmationMail = function sendConfirmationMail(requestEmail, requestCRN, smsRequest, autoRegReq) {
var bodyText="Your Requested Class: " + requestCRN +
(autoRegReq ? "\nYou signed up for automatic registration." :
("\nSigned up for SMS notification: " + (smsRequest ? "yes" : "no") ) ) +
"\n\nThank you for using my service!";
var mailOptions = {
from: "GT Course Watch Mailer ✔ <"+ this._emailID +">", // sender address
to: requestEmail, // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: "Course Watch Confirmation for CRN: " + requestCRN, // Subject line
text: bodyText, // plaintext body
// html: "<b>Hello world ✔</b>" // html body
}
this._smtpTransport.sendMail(mailOptions, function(error, response) {
if(error) console.log(error);
});
}
Mailer.prototype.contactMailJob = function(email, name, msg) {
var bodyText="Name: " + name +
"\nEmail: " + email +
"\n\nMessage: " + msg;
// setup e-mail data with unicode symbols
var mailOptions = {
from: "CONTACT MESSAGE <" + this._emailID + ">", // sender address
to: 'gtcoursewatch.mailer@gmail.com', // list of receivers: "bar@blurdybloop.com, baz@blurdybloop.com"
subject: "CONTACT MESSAGE FROM " + name, // Subject line
text: bodyText, // plaintext body
}
this._smtpTransport.sendMail(mailOptions, function(error, response) {
if(error) console.log(error);
});
}
module.exports = Mailer;