Skip to content

Instantly share code, notes, and snippets.

View yangchangming's full-sized avatar

Huichang yangchangming

View GitHub Profile
@ihsangan
ihsangan / index.js
Last active August 30, 2024 08:42
Send email from Workers with MailChannel API
async function readRequestBody(request) {
const { headers } = request;
const contentType = headers.get('content-type') || '';
if (contentType.includes('application/json')) {
return JSON.stringify(await request.json());
} else if (contentType.includes('form')) {
const formData = await request.formData();
const body = {};
for (const entry of formData.entries()) {
body[entry[0]] = entry[1];