-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
33 lines (29 loc) · 803 Bytes
/
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
const { SES } = require("aws-sdk");
const ses = new SES({ region: "us-east-1" });
exports.handler = async function (event) {
const { name, email, message } = JSON.parse(event.body);
const emailParams = {
Destination: { ToAddresses: ["your-email@gmail.com"] },
Message: {
Body: {
Text: { Data: `Name: ${name}\nEmail: ${email}\nMessage: ${message}` },
},
Subject: { Data: "New form submission" },
},
Source: "your-email@gmail.com",
};
try {
await ses.sendEmail(emailParams).promise();
console.log("Email sent successfully!");
return {
statusCode: 200,
body: "Email sent successfully",
};
} catch (err) {
console.log("Error:", err);
return {
statusCode: 500,
body: "Error sending email",
};
}
};