MailSlurp logo

automations

Email Parser for Reliable Inbound Workflows

Turn inbound emails and attachments into structured records with MailSlurp, then validate, route, and replay each result safely.

An email parser reads inbound messages and attachments, extracts the fields you care about, and returns a structured record. With MailSlurp, the inbox, extraction schema, result history, and webhook delivery can live in one workflow.

That makes the parser useful for more than a one-off demo. You can trace a result back to its source message, reject incomplete data before it reaches another system, and replay delivery without asking someone to copy values from an inbox.

Choose the right extraction method

The best method depends on how consistent the incoming messages are.

Incoming email Recommended approach Example
One stable template with fixed labels Rules or strict selectors A system alert with the same fields every time
Several recognizable templates Route by sender or subject, then apply a schema per message class Order confirmations from known suppliers
Varied wording or document layouts AI extraction with a typed output schema Invoices and shipping notices from many vendors
High-consequence fields AI or rules followed by validation and review Payment details, totals, or identity documents

Many production workflows are hybrid. Use deterministic routing for facts you already know, such as the sender or subject, then use a schema-driven transformer for the variable message body or attachment.

A dependable parser has four stages

1. Capture the original message

Receive the email in a dedicated MailSlurp inbox or connect an existing Gmail or Outlook account. Keep the source email ID and attachment IDs with the resulting record so an operator can inspect the original evidence later.

2. Define the record you need

Describe the output as a JSON schema instead of relying on an open-ended summary. For an invoice, that may include invoice_number, supplier, total, currency, due_date, and line items. Mark genuinely required fields as required; do not invent defaults for values that are absent from the message.

3. Validate before taking action

Check the result against the schema and your business rules. A syntactically valid total can still be unusable if the currency is missing, while a delivery update without an order ID cannot update the correct record. Send uncertain or incomplete results to a review path rather than silently writing them downstream.

4. Deliver with a replay-safe identity

Attach a webhook to the transformer to receive NEW_AI_TRANSFORM_RESULT events. The payload includes an idempotent messageId, an aiTransformResultId, the transformer ID, and the source entity ID when available. Store those identifiers before writing to a CRM, database, spreadsheet, or queue so a retried webhook does not create a duplicate.

Example: turn an invoice email into a record

Suppose suppliers send invoices using different layouts. A useful parser result might look like this:

{
  "invoice_number": "INV-2048",
  "supplier": "Northwind Parts",
  "total": 1840.5,
  "currency": "USD",
  "due_date": "2026-09-15",
  "purchase_order": "PO-7712"
}

The surrounding workflow matters as much as the extraction. Match the message to the invoice transformer, validate that the total and currency are present, compare the purchase order with your records, and only then send the result to the finance system. If validation fails, retain the source email and transform result for review and replay.

Test with the emails that usually cause trouble

A useful trial should include more than a few clean examples. Build a fixture set with:

  • each important sender and template;
  • forwarded and replied-to messages with quoted text;
  • missing, renamed, and multiple attachments;
  • regional date and number formats;
  • absent optional fields and invalid required fields;
  • duplicate delivery of the same webhook event.

Measure whether the resulting record is usable, not merely whether the parser returned JSON. A successful run has the correct source reference, passes validation, reaches the intended destination once, and can be replayed safely after a temporary failure.

Continue with the part you are building