-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
54 lines (50 loc) · 1.11 KB
/
handler.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
47
48
49
50
51
52
53
54
'use strict';
let AWS = require('aws-sdk');
let ses = new AWS.SES({
apiVersion: process.env.API_VERSION,
accessKeyId: process.env.ACCESS_KEY_ID,
secretAccessKey: process.env.SECRET_ACCESS_KEY,
region: process.env.REGION
});
module.exports.sendEmail = async (event) => {
let body = JSON.parse(event.body);
let params = {
Destination: {
CcAddresses: body.ccAddresses || [],
BccAddresses: body.bccAddresses || [],
ToAddresses: body.toAddresses
},
Message: {
Body: {
Html: {
Data: body.body,
Charset: 'utf-8'
},
Text: {
Data: body.textBody,
Charset: 'utf-8'
}
},
Subject: {
Data: body.subject,
Charset: 'utf-8'
}
},
Source: body.sender
};
return await ses.sendEmail(params).promise().then(function (data) {
return {
statusCode: 200,
body: JSON.stringify({
message: data
}),
};
}).catch(function (err) {
return {
statusCode: err.statusCode || 500,
body: JSON.stringify({
message: err,
}),
};
});
};