forked from ericraio/parse-server-simple-ses-adapter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
43 lines (34 loc) · 1.05 KB
/
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
40
41
42
43
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,
};
if (sesOptions.format === 'text') {
data.altText = mail.text;
} else {
data.message = mail.text;
}
return new Promise((resolve, reject) => {
client.sendEmail(data, function(err, body, res) {
if (typeof err !== 'undefined' && err) {
console.log(err);
}
resolve(body);
});
});
};
return Object.freeze({
sendMail: sendMail
});
};
module.exports = SimpleSESAdapter;