Email to webhook: send email data and attachments to an API or Zapier automatically

Email to webhook, automatically: Mail Attachment Downloader sends invoice data, fields and attachments from email to any API or a Zapier Zap.

Mail Attachment Downloader's Web hook step on the rule Acme invoices: POST to https://erp.contoso.com/api/bills as JSON with the invoice number, supplier, due date and total from the email's fields, the saved file sent along, the answer kept in {BILL}, an Authorization header, a 30-second timeout and 3 retries

To send email to a webhook, let a rule pick the emails and add a Web hook step to it. Mail Attachment Downloader then calls your web address for each email or saved file, with a body built from the email’s fields and the values it found, and the attachments too if you want them. For Zapier there is a ready-made Send to Zapier step that starts a Zap the same way.

The examples use Contoso’s mailbox finance@contoso.com, invoices from Acme and Northwind, and invoice numbers like INV-2026-0423.

What can you do with email to webhook?

Anything a system does when it is called. Some common ones:

  • Post invoice data to an accounting API: the invoice number, due date and total from Acme’s PDF go to your accounting system as a new bill, with the PDF attached.
  • Start a Zap: Zapier adds a row to a Google Sheet, creates a task in your task app or posts to a channel for each order email.
  • Open a ticket: a support or service desk system gets the sender, subject and text of each email to a shared mailbox.
  • Hand a file to another program: an internal service that reads, checks or stores documents.

What you need

  • The edition: Web hook, Send to Zapier, Run a script and Run a command line are steps of PRO Rules Server.
  • Windows: Windows 10 or later, 64-bit, on a PC, a server or a cloud VM. No Outlook needed.
  • The mailbox: Gmail, Google Workspace, Microsoft 365, Outlook.com, Exchange, or any IMAP or POP3 mailbox.
  • The address: the web address (endpoint) to call, and its key or token if it needs one.

How to send email data to an API with the Web hook step

1. Make a rule and find the values

On the PRO Rules tab, click New rule…. Under Which emails, add a condition such as the sender’s domain acme.example, and under Save, save the attachments. New to rules? Save emails and attachments to folders walks through a first one.

The email’s own details are fields already: {FROM}, {SUBJECT}, {DATE} and many more (see fields). Values inside the attachment, such as the invoice number or the total, come from Find fields in the file (patterns), Find fields with AI or the Parser. Put the web hook after or inside that step, so it can use them.

Rule Editor of Mail Attachment Downloader for the rule Scanned invoices: Find fields with AI fills INVOICE_NUMBER, DUE_DATE and TOTAL_INCLUDING_TAX, and the Web hook step inside it sends the values to an API
Find fields with AI reads the invoice; the Web hook step inside it sends the values on.

2. Add the Web hook step

Under Then, click Add a step…, choose Other systems and double-click Web hook. Select a step first to add the new one after it or inside it; Add it says where.

Add a step window in Mail Attachment Downloader with Other systems chosen: Upload to cloud, Send to document management, Send for signature, Send to Zapier and Web hook, the step that sends email data to an API
Add a step › Other systems › Web hook.

3. Set the address, method and body

  • Address: the web address to call, such as https://erp.contoso.com/api/bills. Fields work here too; their values are URL-encoded, so ?invoice={INVOICE_NUMBER} is safe.
  • Method: POST (the default), PUT, PATCH, GET or DELETE.
  • Content type: application/json by default; XML, plain text, a form and others are in the list.
  • Body: what is sent, with fields in it. Click Fields… to pick one.

A body for Acme’s invoice could be:

{
  "invoice": "{INVOICE_NUMBER}",
  "supplier": "{EMAIL_FROM}",
  "due": "{DUE_DATE}",
  "total": "{TOTAL_INCLUDING_TAX}"
}

Each value is escaped for where it goes, so a value with quotes or a line break can’t break the JSON. Run decides how often it is called: For each saved file (the default) or Once per email.

Mail Attachment Downloader's Web hook step on the rule Acme invoices: POST to https://erp.contoso.com/api/bills as JSON with the invoice number, supplier, due date and total from the email's fields, the saved file sent along, the answer kept in {BILL}, an Authorization header, a 30-second timeout and 3 retries
The Web hook step: send the email’s fields as JSON to any API, with the file, headers and retries.

4. Headers, files and retries

  • Send files: None: only the body, The file it runs for, or Every file the rule saved from the email so far. With files, the call is sent as a form: the body in a field named payload, and each file as a file.
  • Headers: under More options, Add a header adds one, such as Authorization with Bearer and your API key, or an API key header your service asks for.
  • Timeout (seconds) and Retries: 30 seconds and 3 retries by default. A call that gets no connection, no answer in time, or HTTP 408, 429 or a server error is tried again after 2, 4, 8… seconds. An answer like 400 or 401 isn’t, since the same call would get the same answer.

If it still fails, the step fails: the Downloads tab shows it, the steps under If something fails run, and the email’s History tries the step again later. History also keeps the address without its query, which can hold a key.

5. Test it

Click Test the web hook. It calls the address once with a sample email’s values and shows the answer. Then click Save, and Test this rule… to see which emails the rule picks; the test only describes the call, it doesn’t make it.

Keep fields from the API’s answer

The answer is kept in the field named in Save the answer in, such as {BILL}. Steps inside the web hook, and the steps after it, can use it. When the answer is JSON, a Fill a template (Handlebars) step picks out what you need: with {{id}} as its template, the bill’s ID from your accounting system becomes a field for a file name, a database row or a notification.

How do I send email to Zapier?

With Send to Zapier. It is the web hook step set up for a Zap that starts with Webhooks by Zapier, so there is no method or content type to choose.

  1. In Zapier, make a Zap with Webhooks by Zapier and the Catch Hook event, and copy its web address.
  2. In the rule, click Add a step… › Other systems › Send to Zapier.
  3. Paste the address into Zap’s address.
  4. Check Fields to send. It starts with the sender, subject, date, account and save path, plus the fields your rule finds. Add more with Fields….
  5. Click Send a sample to Zapier, then Test trigger in Zapier to see the fields.
Add a step window with the Send to Zapier step selected: starts a Zap with the email's fields (Webhooks by Zapier, Catch Hook)
Send to Zapier is in Add a step › Other systems.

It runs Once per email. Files go only if you choose them under More options; the step says what leaves the computer: the fields to send, and those files, to hooks.zapier.com.

Send to Zapier step in the Rule Editor for the rule Orders to Zapier: Zap's address https://hooks.zapier.com/hooks/catch/..., Fields to send with from, subject, date, account_email and save_path, Run Once per email, and Send a sample to Zapier
Send to Zapier: paste the Zap’s address and choose the fields to send.

In Zapier, add the actions that use the fields: Google Sheets’ “Create Spreadsheet Row” to log each Northwind order, or a task app’s create-task action with the subject as the task name. Same retries as the web hook, and the answer is kept the same way.

Run a script or a command line instead

When the work is on your own system rather than behind a web address, use Add a step… › Programs:

  • Run a script: a PowerShell script, a .bat or .cmd file, or a program, with the fields in its Arguments, and a Timeout (seconds).
  • Run a command line: a program or a .bat file, with arguments such as --supplier "{SUPPLIER}" --file "{SAVE_PATH}\{FILENAMEEXT}".

Click Run it once (test) to try it with a sample email’s values. Both are PRO Rules Server steps. More in email actions: run a script.

Run a command line step in the Rule Editor for the rule Supplier invoices: Command C:\Tools\ArchiveInvoice.exe, Arguments with the SUPPLIER, SAVE_PATH and FILENAMEEXT fields, Run For each saved file, and Run it once (test)
Run a command line: a program gets the fields as arguments.

Questions people ask

Can I send email attachments to a webhook?

Yes. Set Send files to The file it runs for or Every file the rule saved from the email so far. They are sent as a form upload with the body.

Does it work with Make, n8n or Power Automate?

Any service that gives you a web address to call works with the Web hook step. Send to Zapier is only a shortcut for Zapier.

Will the same email be sent twice?

No. Each account’s History remembers the emails it has handled, so the next run doesn’t call the address for them again.

Does the program have to be running?

Yes, or run it as the Windows service of PRO Rules Server, which works 24×7, even when nobody is signed in.

Try it: download Mail Attachment Downloader and start with the free edition, or compare the PRO editions, each with a 30-day money-back guarantee.

Related

Questions about this post? Contact us.