-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (31 loc) · 996 Bytes
/
index.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
var ses = require('node-ses');
var SimpleSESAdapter = sesOptions => {
if (!sesOptions || !sesOptions.apiKey || !sesOptions.apiSecret || !sesOptions.domain || !sesOptions.fromAddress) {
throw 'SimpleSESAdapter requires an API Key, domain, and fromAddress.';
}
if(!sesOptions.amazon){
sesOptions.amazon = 'https://email.us-east-1.amazonaws.com'
}
var client = ses.createClient({ key: sesOptions.apiKey, secret: sesOptions.apiSecret, amazon : sesOptions.amazon });
var sendMail = mail => {
var data = {
to: mail.to,
from: sesOptions.fromAddress,
subject: mail.subject,
altText: mail.text,
};
return new Promise((resolve, reject) => {
client.sendEmail(data, function(err, body, res) {
if (typeof err !== 'undefined') {
console.log(err);
reject(err);
}
resolve(body);
});
});
};
return Object.freeze({
sendMail: sendMail
});
};
module.exports = SimpleSESAdapter;