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 July 19, 2024 02:54
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];