-
Notifications
You must be signed in to change notification settings - Fork 0
/
handler.js
53 lines (49 loc) · 1.55 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
'use strict';
var ses = require('node-ses')
const client = ses.createClient({ key: process.env.SES_KEY, secret: process.env.SES_SECRET });
const sendMail = async (subject, message, to)=> {
let res = false;
return new Promise((resolve , reject)=>{
client.sendEmail({
to: to
, from: process.env.SENDER_EMAIL
, subject: subject
, message: message
, altText: 'plain text'
}, function (err, data, res) {
console.log('err', err)
if (err) { reject(err); return }
console.log('data', data)
console.log('res', res)
resolve(data);
return
});
})
}
module.exports.mailer = async (event) => {
const eventData = JSON.parse(event.body);
const {subject, message, to} = eventData
// const message = `Request received from ${name} email: ${email}`
const res = await sendMail(subject, message, to)//then( res => {
return {
statusCode: 200,
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
body: JSON.stringify({
message: `Go Serverless v1.0! Your function executed successfully! with status ${res}`,
}, null, 2),
};
// }
// ).catch( err=>{
// return {
// statusCode: 200,
// body: JSON.stringify({
// message: `Go Serverless v1.0! Your function executed successfully! with status false`,
// }, null, 2),
// };
// })
// Use this code if you don't use the http event with the LAMBDA-PROXY integration
// return { message: 'Go Serverless v1.0! Your function executed successfully!', event };
};