-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
46 lines (42 loc) · 1.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
const axios = require("axios");
exports.handler = async (event, context) => {
try {
const { email, name, content } = JSON.parse(event.body); // Parse the incoming JSON body
const apiKey = process.env.BREVO_API_KEY; // Use the API key from environment variable
const response = await axios.post(
"https://api.sendinblue.com/v3/smtp/email",
{
sender: { name: "Daman Mokha", email: "daman@damanmokha.com" },
to: [{ email: "damanmokha24@gmail.com" }],
subject: "New Contact on site",
htmlContent: `
<p>Someone contacted on site.</p>
<table border="1">
<tr><td>Name:</td><td>${name}</td></tr>
<tr><td>Email:</td><td>${email}</td></tr>
<tr><td>Content:</td><td>${content}</td></tr>
</table>
`,
},
{
headers: {
"Content-Type": "application/json",
"api-key": apiKey,
},
}
);
return {
statusCode: 200,
body: JSON.stringify({
message: "Email sent successfully",
response: response.data,
}),
};
} catch (error) {
console.error("Error sending email:", error);
return {
statusCode: 500,
body: JSON.stringify({ error: "Error sending email" }),
};
}
};