Skip to main content

Posts

Featured

Handling emails with node.js and Mailparser

After sorting out mail forwarding and piping emails with postfix, I then needed to understand how to handle emails being POSTed to an API endpoint.

To parse an email with node.js, I recommend using Mailparser's simpleParser. I'm using express with bodyParser configured as follows:
app.use(bodyParser.json({ limit : config.bodyLimit }));In your handler:
const express = require('express'); const router = express.Router(); const simpleParser = require('mailparser').simpleParser;or
import { Router } from 'express'; import { simpleParser } from 'mailparser';and thenapi.post('/', (req, res) => { simpleParser(req) .then(parsed => { res.json(parsed); }) .catch(err => { res.json(500, err); }); }); Mailparser is excellent, and documented, but the documentation assumes that we're familiar with the email format. Fortunately, oblac's example email exists for those of us who are…

Latest posts

Mail forwarding and piping emails with Postfix for multiple domains

FreeVote: anonymous Q&A app

Hosting my own podcast

Effective Technical Interviewing with GitHub

C# / OPENSSH RSA ENCRYPTION MADE EVEN EASIER

Sonnet Comix patreon campaign now open!

self-signed localhost ssl certificate on windows (for dummies)

IIS Rewrite Rules Regex

Sale!

Azure Key Vault in C# for Dummies