-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
100 lines (85 loc) · 2.27 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
const AWS = require('aws-sdk');
// Set the region
const ses = new AWS.SES({ region: 'us-east-1' });
exports.handler = async (event) => {
if (!event.body) {
return;
}
const body = JSON.parse(event.body);
if (!body.message) {
return;
}
const pubSubMessage = body.message;
const message_data = JSON.parse(Buffer.from(pubSubMessage.data, 'base64').toString());
let params;
switch (message_data.type) {
case "verify_email":
params = {
Destination: {
ToAddresses: [message_data.recipient] // Replace with your own email address
},
Message: {
Body: {
Text: {
Data: `${message_data.email_text} \n ${message_data.verify_email_link}`
}
},
Subject: {
Data: `${message_data.subject}`
}
},
Source: 'Verify Email <support@tikitiki.me>' // Replace with your own email address
};
break;
case "forgot_password":
params = {
Destination: {
ToAddresses: [message_data.recipient] // Replace with your own email address
},
Message: {
Body: {
Text: {
Data: `${message_data.email_text} \n ${message_data.verify_email_link}`
}
},
Subject: {
Data: `${message_data.subject}`
}
},
Source: 'Password Reset <support@tikitiki.me>' // Replace with your own email address
};
break;
case "claims":
params = {
Destination: {
ToAddresses: [message_data.recipient] // Replace with your own email address
},
Message: {
Body: {
Text: {
Data: `${message_data.email_text}`
}
},
Subject: {
Data: `${message_data.subject}`
}
},
Source: 'TikiTiki Prize Claims <support@tikitiki.me>' // Replace with your own email address
};
break;
default:
break;
}
try {
const result = await ses.sendEmail(params).promise();
console.log(result);
const response = {
statusCode: 200,
body: JSON.stringify('Email sent successfully.')
}
return response;
} catch (err) {
console.log(err);
return err;
}
};