-
Notifications
You must be signed in to change notification settings - Fork 0
/
mailer.js
46 lines (43 loc) · 1.28 KB
/
mailer.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
/**
* Created by Suyash on 17/02/18.
*/
const AWS = require('aws-sdk');
const SES = new AWS.SES({
accessKeyId: process.env.ACCESS_KEY_SES,
secretAccessKey: process.env.SECRET_KEY_SES,
region: "us-west-2",
endpoint: new AWS.Endpoint('https://email.us-west-2.amazonaws.com')
});
// to_mail => receiver's mail address (e.g. [email protected] )
// from_mail => sender's mail initials (e.g. admin, events, guest etc.)
// subject => Email Subject
// body => body of mail (supports html formatting)
// sender_name => Name of sender to display (e.g. Admin Tryst IITD)
function sendMail(to_mail, from_mail, subject, body, sender_name = "Status Board") {
const params = {
Destination: {
ToAddresses: [to_mail]
},
Message: {
Body: {
Html: {
Data: body
},
},
Subject: {
Data: subject
}
},
Source: sender_name + "\<" + from_mail + "@devclub.in\>",
};
SES.sendEmail(params, function (err, data) {
if (err) {
console.log("SES err: ", err);
} else {
console.log("Mail sent to: " + to_mail + " with subject: " + subject);
}
});
}
module.exports = {
sendMail: sendMail,
};