-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathmain.js
More file actions
60 lines (46 loc) · 961 Bytes
/
main.js
File metadata and controls
60 lines (46 loc) · 961 Bytes
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
/**
* Example implementation of Amazon Simple Email Service (Amazon SES)
*
* @author Maciej Lisowski
* @since 2018-11-25
*/
// import AWS SDK
const AWS = require('aws-sdk');
const { REPLY_TO, MAIL_FROM } = require('./awsConfig')
class AwsSes {
constructor(config) {
this.ses = new AWS.ses(config)
}
sendMail({ toAddress, subject, body }) {
var params = {
Source: MAIL_FROM,
Destination: {
ToAddresses: [
toAddress
]
},
ReplyToAddresses: [
REPLY_TO
],
Message: {
Body: {
Html: {
Charset: "UTF-8",
Data: body
}
},
Subject: {
Charset: 'UTF-8',
Data: subject
}
}
};
try {
const result = this.ses.sendEmail(params).promise()
return result['messageId']
} catch (error) {
return new Error(error)
}
}
}
module.exports = AwsSes