-
Notifications
You must be signed in to change notification settings - Fork 1
/
PostMarkClient.js
43 lines (38 loc) · 987 Bytes
/
PostMarkClient.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
const request = require('request');
const POSTMARK_URL = 'https://api.postmarkapp.com/email';
class PostMarkClient {
constructor () {
this.url = POSTMARK_URL;
this.serverToken = '49e6346c-8c40-4f8b-b8b9-9b373ebe66e1';
}
getOptions ({to, subject, html}) {
return {
url: this.url,
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
'X-Postmark-Server-Token': this.serverToken
},
body: JSON.stringify({
From: '[email protected]',
To: to[0],
Subject: subject,
HtmlBody: html
})
};
}
sendMail (data) {
return new Promise((resolve, reject) => {
const options = this.getOptions(data);
request(options, (err, response, body) => {
if (err || response.statusCode !== 200) {
reject(err);
} else {
resolve({body});
}
});
});
}
}
module.exports = PostMarkClient;