Skip to main content

Frameworks

Express

Send email from an Express route — pass req.body straight to mail().


Express’s built-in express.urlencoded() parses a submitted form into a plain object on req.body — and mail() accepts that object directly, no extra dependency needed. Postboi extracts the special fields and renders the rest into a tidy HTML table.

// src/server.js
import express from 'express'
import { mail } from 'postboi'

const app = express()
app.use(express.urlencoded({ extended: true })) // parses form fields onto req.body

app.post('/contact', async ({ body }, res) => {
	await mail({ body })
	res.redirect(303, '/?sent=1')
})

app.listen(3000)
// src/server.js
import express from 'express'
import { mail } from 'postboi'

const app = express()
app.use(express.urlencoded({ extended: true })) // parses form fields onto req.body

app.post('/contact', async ({ body }, res) => {
	await mail({ body })
	res.redirect(303, '/?sent=1')
})

app.listen(3000)

Point a form at /contact. Include hidden _subject and _reply_to fields, and mirror the email into _reply_to with a one-line oninput so replying reaches the sender. Field names use the fieldset→field syntax.

A urlencoded form can’t carry files. For attachments, switch to enctype="multipart/form-data" and parse it with a multipart parser like multerreq.body still flows into mail({ body }) the same way.

The provider and default recipient come from postboi.config.js — a POSTBOI_TOKEN routes to Postboi Cloud, or pick any provider.

Runnable example: examples/express-provider-postboi.