Skip to content
Docs menu

Capture by email

Have your own mail provider (Postmark, SendGrid, Mailgun) post the invoices and receipts it receives into Finance > Documents. Turning it on, the secret, provider setup, each entity's address, allowed senders and held mail, the limits, what is stored, and turning it off.

View .md

Capture by email lets suppliers and colleagues send invoices, receipts and statements to an email address. Your own mail provider receives the mail and posts each message to Petawork, and each usable attachment becomes a document in Finance > Documents, with the same type checks and exact-duplicate detection as an upload.

It belongs to the Capture module (finance.capture) and is off until an owner or admin turns it on. Petawork only receives: it never sends mail, fetches a link or loads an image from a message. You bring the mail provider and the inbound domain.

Turning it on

  1. Open Finance > Settings > Capture by email (/finance/settings/email). You need a Finance role that changes policies: owners, admins and members with the controller role.
  2. Turn the switch on. Petawork makes the inbound secret and shows it once, as two ready URLs: one with the secret in the query (?secret=) and one with it as the HTTP Basic auth password. Copy the one your provider needs.
  3. Set up the provider (below) with that URL.
  4. Add the senders whose mail should be processed (below), and save.

The secret is sealed in the vault. It is never shown again, and no screen, tool or log returns it. If it is lost, press Make a new secret: the old one stops working at once, so paste the new URL into the provider straight away.

The vault must be set up (VENOM_VAULT_KEYS). Without it, turning Capture by email on or making a secret answers 503 vault_not_configured.

Setting up your provider

The endpoint is POST /api/integrations/finance-inbound/{organisation id}, shown in full on the settings page. The secret can travel as ?secret=, the x-venom-finance-secret header, or the password of HTTP Basic auth (any user name).

Provider What to do
Postmark Open your server's Inbound stream and set the webhook URL to the Basic auth form, https://x:SECRET@your-petawork/api/integrations/finance-inbound/…. Leave Include raw email content off.
SendGrid Under Settings > Inbound Parse, add your receiving host and point it at the URL with ?secret=. Leave POST the raw, full MIME message off: Petawork reads the parsed fields and files.
Mailgun Create a route that matches your receiving address, with the action forward("…?secret=…"). Mailgun posts the parsed message with its attachments.
Another forwarder Post JSON (from, subject, text, attachments: [{name, content}] with base64 content) or form fields and files, with the secret in any of the three places.

Pick the provider on the settings page to see its steps there too.

Each entity's address

If you enter your inbound address at the provider (for example invoices@in.example.com), the page shows an address for each entity: the same address with a plus tag, such as invoices+3f9c0a71d2@in.example.com. Mail sent to an entity's address lands on that entity. Mail sent to the plain address arrives with no entity yet, as an upload without one does. The tag only routes mail; the secret is what lets a message in. Your provider must deliver plus-addressed mail to the same route (Postmark does this by default and passes the tag as MailboxHash).

Allowed senders and held mail

The allowed senders are addresses (ap@supplier.example) or domains (acme.com, which matches that exact domain, not its subdomains), up to 100. Mail from anyone else is held, not processed: it waits under Held mail on the settings page with its subject, a masked sender, its plain-text body and its attachments' names.

  • Release turns each held attachment into a document, sent in under your name.
  • Dismiss deletes the held attachments. The delivery log keeps the row.

An empty list holds every message, so add your suppliers or your own domain before relying on it. Only a person with a controller's rights releases or dismisses held mail; an agent never does.

What happens to a message

Outcome Meaning
Accepted At least one attachment became a document
Duplicate Every usable attachment was already in Finance (the same bytes), so each is kept as a duplicate pointing at the original, not stored again
Held The sender is not on the list; waiting for a person
Refused Nothing usable: no attachment, or only refused ones. The reason is in the log
Released, Dismissed A held message a person decided

The same message delivered twice (a provider's retry, matched by its message id) is stored once; the log counts the repeats. A message with a body and no attachment stores nothing and is logged as refused, no attachment.

Each attachment is checked on its own, and the log shows each one's result: stored, duplicate, held, ignored (a small inline picture such as a logo or signature image, under 20 KB) or refused with the reason (too large, too many, SVG, HTML, a type Finance does not take, the files quota).

Limits

  • 4 MB per message as the provider posts it; a larger message is refused with 413 and nothing is kept.
  • 3 MB per attachment, and 10 attachments per message; the rest are refused by name.
  • 120 messages a minute per organisation; more answer 429 with Retry-After, and providers retry.
  • The plain-text body is kept up to 4,000 characters. HTML is never kept or shown: when a message has no text part, its tags are stripped and only the text is kept.
  • Attachments count toward the organisation's files quota, held ones included.
  • The delivery log keeps 90 days. Held mail stays until someone decides.

What is stored, and what is not

  • Each accepted attachment, as a document with source email, the sender recorded as email: and a hash of the address, and a link (source_ref) to its message in the log.
  • In the log: when it arrived, the provider, the entity, the subject, a masked sender (a…@supplier.example) and its domain, the outcome and each attachment's name, size and result. The body only for accepted and held mail.
  • On the audit trail: an event per message (finance.inbound.accepted, .duplicate, .held, .refused, .released, .dismissed), one per document received, and one per settings change, written by system as email:<hash>.
  • Never: the secret, the raw request, the full sender address, the HTML, or an attachment's bytes outside the document store.

The attachment's declared type and file name are not trusted. The type is read from the bytes, and the name is cleaned of folders and control or markup characters.

Turning it off

Turn the switch off on the settings page, or call finance_inbound_update with {"enabled": false}. The endpoint then answers 404 and stores nothing. The secret is kept, so turning it back on works with the URL your provider already has; make a new secret if you want the old one gone. An organisation without Capture gets 404 at the endpoint whatever its settings.

Errors at the endpoint

Status When
404 not_found Capture by email is off, has no secret, Capture is not on the plan, or the organisation does not exist
401 invalid_secret The secret is missing or wrong. Checked before the body is read
413 payload_too_large Over 4 MB
422 unparseable No valid sender address
429 rate_limit_exceeded Over 120 messages a minute
200 Read. The body says accepted, duplicate, held, refused or repeat

For agents

Tool What it does OAuth scope
finance_inbound_get The settings (on or off, provider, address, whether a secret is set and its last four characters, allowed senders), the endpoint, each entity's address, the last 20 deliveries and the held mail finance:read
finance_inbound_update Change enabled, provider, address, allowed_senders, or rotate_secret: true for a new secret, returned once in this answer finance:admin

REST twins: GET /api/v1/finance/inbound and PATCH /api/v1/finance/inbound. No tool takes a secret. Reading needs capture.read (controller, AP or AR clerk, auditor). Changing it needs a controller's rights and is refused for an agent, whatever its roles. Releasing and dismissing held mail is on the page only.