Skip to content

Commit bb7e24f

Browse files
committed
Update worker to use MailLayer transactional API
- Use mail.simplebytes.com endpoint - Pass apiKey (template ID) in body instead of Bearer token - Add email templates for reference
1 parent a777ab0 commit bb7e24f

File tree

4 files changed

+67
-11
lines changed

4 files changed

+67
-11
lines changed

worker/contact-form.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,9 @@
88
*
99
* Environment variables required:
1010
* - TURNSTILE_SECRET_KEY: Cloudflare Turnstile secret key
11-
* - MAILLAYER_API_KEY: MailLayer API key
1211
* - CONFIRMATION_TEMPLATE_ID: MailLayer template ID for user confirmation
1312
* - ADMIN_TEMPLATE_ID: MailLayer template ID for admin notification
1413
* - ADMIN_EMAIL: Email to receive submissions (default: hello@simplebytes.com)
15-
* - FROM_EMAIL: Email to send from (e.g., noreply@simplebytes.com)
1614
*
1715
* Template variables available:
1816
* - [name]: Sender's name
@@ -155,17 +153,15 @@ async function verifyTurnstile(token, secretKey) {
155153
}
156154

157155
async function sendEmail(env, { to, replyTo, templateId, variables }) {
158-
const response = await fetch('https://api.maillayer.com/v1/send', {
156+
const response = await fetch('https://mail.simplebytes.com/api/transactional/send', {
159157
method: 'POST',
160158
headers: {
161-
'Authorization': `Bearer ${env.MAILLAYER_API_KEY}`,
162159
'Content-Type': 'application/json',
163160
},
164161
body: JSON.stringify({
165-
from: env.FROM_EMAIL || 'noreply@simplebytes.com',
162+
apiKey: templateId,
166163
to,
167-
reply_to: replyTo,
168-
template_id: templateId,
164+
replyTo,
169165
variables,
170166
}),
171167
});
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
</head>
7+
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #171717; max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fafafa;">
8+
<div style="background: #ffffff; border-radius: 12px; padding: 32px; border: 1px solid #e5e5e5;">
9+
<div style="border-bottom: 1px solid #e5e5e5; padding-bottom: 20px; margin-bottom: 24px;">
10+
<h1 style="font-size: 24px; font-weight: 600; margin: 0; color: #171717;">New Contact Form Submission</h1>
11+
</div>
12+
13+
<div style="background: #f5f5f5; border-radius: 8px; padding: 20px; margin-bottom: 20px;">
14+
<p style="margin: 0 0 12px 0;"><strong>Name:</strong> [name]</p>
15+
<p style="margin: 0 0 12px 0;"><strong>Email:</strong> <a href="mailto:[email]" style="color: #2563eb;">[email]</a></p>
16+
<p style="margin: 0 0 12px 0;"><strong>Project:</strong> [project]</p>
17+
<p style="margin: 0;"><strong>Topic:</strong> [topic]</p>
18+
</div>
19+
20+
<div style="background: #fafafa; border: 1px solid #e5e5e5; border-radius: 8px; padding: 20px;">
21+
<p style="margin: 0 0 12px 0;"><strong>Message:</strong></p>
22+
<p style="margin: 0; white-space: pre-wrap;">[message]</p>
23+
</div>
24+
25+
<p style="margin-top: 20px; font-size: 13px; color: #737373;">
26+
Reply directly to this email to respond to [name].
27+
</p>
28+
</div>
29+
</body>
30+
</html>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
</head>
7+
<body style="font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; line-height: 1.6; color: #171717; max-width: 600px; margin: 0 auto; padding: 20px; background-color: #fafafa;">
8+
<div style="background: #ffffff; border-radius: 12px; padding: 32px; border: 1px solid #e5e5e5;">
9+
<div style="border-bottom: 1px solid #e5e5e5; padding-bottom: 20px; margin-bottom: 24px;">
10+
<h1 style="font-size: 24px; font-weight: 600; margin: 0; color: #171717;">Simple Bytes</h1>
11+
</div>
12+
13+
<p style="margin: 0 0 16px 0;">Hi [name],</p>
14+
15+
<p style="margin: 0 0 24px 0;">Thank you for reaching out! We've received your message and will get back to you as soon as possible.</p>
16+
17+
<div style="background: #f5f5f5; border-radius: 8px; padding: 20px; margin: 0 0 24px 0;">
18+
<p style="margin: 0 0 12px 0;"><strong>Project:</strong> [project]</p>
19+
<p style="margin: 0 0 12px 0;"><strong>Topic:</strong> [topic]</p>
20+
<p style="margin: 0 0 12px 0;"><strong>Your message:</strong></p>
21+
<p style="margin: 0; white-space: pre-wrap; color: #525252;">[message]</p>
22+
</div>
23+
24+
<p style="margin: 0;">Best regards,<br><strong>The Simple Bytes Team</strong></p>
25+
26+
<div style="border-top: 1px solid #e5e5e5; padding-top: 20px; margin-top: 24px; font-size: 12px; color: #737373;">
27+
<p style="margin: 0 0 8px 0;">This is an automated confirmation. Please do not reply to this email.</p>
28+
<p style="margin: 0;"><a href="https://simplebytes.com" style="color: #525252;">simplebytes.com</a></p>
29+
</div>
30+
</div>
31+
</body>
32+
</html>

worker/wrangler.toml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ account_id = "4963e2d7410e0650e45f31d098a84880"
99
[vars]
1010
ADMIN_EMAIL = "hello@simplebytes.com"
1111
FROM_EMAIL = "noreply@simplebytes.com"
12-
# Add your MailLayer template IDs here:
13-
CONFIRMATION_TEMPLATE_ID = ""
14-
ADMIN_TEMPLATE_ID = ""
12+
CONFIRMATION_TEMPLATE_ID = "txn_694fabb3055c3457fb7a84bd_mjo4ctu0"
13+
ADMIN_TEMPLATE_ID = "txn_694faf26055c3457fb7a84dc_mjo4vraw"
1514

1615
# Secrets (add via `wrangler secret put`):
1716
# - TURNSTILE_SECRET_KEY
18-
# - MAILLAYER_API_KEY

0 commit comments

Comments
 (0)