Inbound Email

Updated Nov 9, 2026
DataMagik Automate

What an inbound address does

DataMagik can give you an email address that starts something when mail arrives: a script, a workflow, or an AI agent. Forward a mailbox to it, such as the one customers send purchase orders to or suppliers send invoices to, and each accepted message runs with its sender, subject, body and attachments.

Each address is set up as a hook on the Script Engine › Inbound Email screen. Managing hooks needs the DataMagik - Security permission.

Creating a hook

  1. Open Script Engine › Inbound Email and click New hook.
  2. Enter a Label (address prefix), such as ap-invoices. It is used once, to start the address.
  3. Choose the Target script: the script or workflow to run for each message, or, if your company has AI Agents, an enabled agent from the AI agents group. A script runs the message; an agent reads it and decides what to do about it.
  4. List the Safe senders, one per line. See Who may send.
  5. Optionally, set a Subject filter (optional).
  6. Leave Enabled ticked, and save.

DataMagik then generates the hosted address, made from the label's letters and digits plus a random part, for example:

apinvoices-3f9c0a1b7d2e4c6f8a9b0c1d@inbound.data-magik.com

The address cannot be changed afterwards. The random part means nobody can guess it, so share it only with the mailbox or people who should use it. Copy it from the hook's row, then forward your mailbox to it with a mail rule in Outlook or Gmail, or ask your mail administrator to.

Hook settings

SettingWhat it does
Label (address prefix)Starts the generated address. Only letters and digits are kept, up to 20.
Target scriptWhat runs for each accepted message. Can be changed at any time.
Safe sendersThe senders allowed to start the target.
Subject filter (optional)Text the subject must contain, in any upper or lower case. Messages whose subject does not contain it are rejected.
Accept any sender (disables the allowlist)Accepts mail from anyone. Anyone who learns the address can then run the target.
EnabledWhen off, mail to the address is not accepted and does not appear in the hook's messages.

The target is stored by name. If you rename the script, edit the hook and choose it again, or messages will be rejected because the target cannot be found.

Who may send

Each line in Safe senders is one of:

EntryMatches
billing@acme.comThat address only.
@acme.comAnyone at acme.com, but not at a subdomain such as eu.acme.com.
@*.acme.comAnyone at a subdomain of acme.com, such as eu.acme.com, but not at acme.com itself. Add both lines to allow both.

Upper and lower case do not matter. Depending on how your mail system forwards, the sender DataMagik sees may be the forwarding mailbox rather than the person who wrote the message. If messages are rejected as not on the allowlist, Received messages shows which sender arrived, so you can add it.

Some messages are always rejected, whatever the allowlist says: bounces and automatic replies (for example "Out of office" or "Undeliverable" subjects, or auto-reply headers), and mail from addresses such as no-reply@, noreply@, donotreply@, mailer-daemon and postmaster@. A system that sends from a no-reply address cannot start a hook directly; forward its mail from a real mailbox.

What the script receives

The target script runs with the message as its context:

function main(context) {
  context.trigger      // "email"
  context.from         // sender address
  context.fromName     // sender display name
  context.to           // the hosted address it was sent to
  context.subject
  context.textBody     // plain-text body
  context.htmlBody     // HTML body
  context.headers      // header names in lower case: { "reply-to": "...", ... }
  context.attachments  // [ { name, contentType, size, base64, document_key }, ... ]
  context.message_id   // the message's id from the mail service
  context.intake_id    // the hook's id
}

Each attachment arrives with its content as base64 in base64. A copy is also saved to your company's document storage, and its key is in document_key. An attachment over 25 MB arrives without content, marked oversized: true, so the script can tell the sender it was too large.

The run appears in Executions with Started by set to Inbound email. The hook only runs the target; reading text from a scanned PDF is up to the script, for example with OCR.

For a workflow, use an Email Arrives trigger instead of choosing the workflow here: choose the hook's address in the trigger, and saving the workflow points the hook at it. The workflow gets the message as one tidy item. See Workflow Triggers.

Received messages and replay

Click Messages on a hook to open Received messages: every message that reached the address, newest first (up to 200), with All, Triggered and Rejected tabs and a Refresh button.

  • Triggered messages started the target. The run's id is shown, and opening the message shows the run's console output, return value, error and any documents it made.
  • Rejected messages show why, without opening them:
    • automated or bounce message
    • sender not on the safe-sender allowlist
    • subject did not match filter
    • could not run the intake's target: … (for example, the script was renamed or deleted)

Open a message to read it. Payload shows exactly what the script received; HTML and Text show the message body. Remote images in the HTML are blocked until you click Load remote content. The console keeps the first 512 KB of each body; the run itself received the whole message.

Replay runs the hook's current target again with the stored message, attachments included. Use it after fixing a script, or after changing the target, to process a message again without asking the sender to resend. The script sees context.replay set to true, so it can skip anything that must happen only once. A rejected message's attachments are not kept, so replaying one runs without its attachment content.

When nothing happens

  • The message is in Received messages as Rejected. The reason says why. Add the sender to Safe senders, fix the subject filter, or fix the target, then use Replay.
  • The message is Triggered, but the result is wrong. Open the run from the message, or find it in Executions, and read its console and error.
  • The message is not listed at all. Check that the hook is Enabled, that the address was copied exactly, and that the mailbox rule actually forwards. The same message delivered twice is processed once.

Retention

Received messages are kept for 180 days. The runs they started follow the Executions retention of 90 days.

Related

Was this page helpful?