-
-
Notifications
You must be signed in to change notification settings - Fork 567
/
contact.js
33 lines (26 loc) 路 829 Bytes
/
contact.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
import * as postmark from 'postmark';
const client = new postmark.ServerClient(process.env.POSTMARK_API_TOKEN);
export default async function handler(request, response) {
const body = request.body;
if (!body.name || !body.email || !body.message) {
return response.status(400).json({ data: 'Invalid' });
}
const subject = `Message from ${body.name} (${body.email}) via jotai.org`;
const message = `
Name: ${body.name}\r\n
Email: ${body.email}\r\n
Message: ${body.message}
`;
try {
client.sendEmail({
From: 'noreply@jotai.org',
To: process.env.EMAIL_RECIPIENTS,
Subject: subject,
ReplyTo: body.email,
TextBody: message,
});
response.status(200).json({ status: 'Sent' });
} catch (error) {
response.status(500).json({ status: 'Not sent' });
}
}