View Categories

Email Routing and IMAP Piping

Email routing turns a mailbox into a ticket queue. RackHelm polls each mailbox you configure, files new messages as tickets in a department you choose, and threads replies back onto the ticket they belong to. It speaks IMAP, POP3 and the Microsoft 365 Graph API. This article is for whoever sets a mailbox up and has to work out why mail is not arriving.

Before you start #

Note: Support → Email Routing requires the manage_email_routes permission. It is deliberately withheld from the built-in Administrator role — a mailbox credential is a sensitive thing to hand out — so only Super Admin has it after a fresh install. Grant it per install from the Roles screen. See Roles & Permissions.

Tip: Anyone holding manage_email_routes sees Email Routing under Support in the sidebar. The screen is also at /admin/email-routes.

You will need:

  • At least one department to route mail into.
  • A dedicated mailbox — support@yourdomain — with its credentials, or an Azure AD app registration for Microsoft 365.
  • The Laravel scheduler cron and a running queue worker on the server. Nothing is polled without them.
  • Your mail server’s authserv-id, if it stamps Authentication-Results headers. See Sender authentication below — this one is easy to miss and stops mail arriving. It is not needed for a Microsoft 365 (Graph) route.

Warning: Sender authentication is required by default. On an IMAP or POP3 route, mail is only bound to a customer account if RackHelm can find an Authentication-Results header stamped by your own MTA — and it cannot recognise one until you have set inbound_mail_trusted_authserv_id. Until then every message becomes an [UNVERIFIED SENDER] ticket owned by a placeholder account. Set the authserv-id before you enable the schedule, or you will spend your first afternoon reattributing tickets by hand.

Adding a route #

The Email Routing list showing routes with an active switch, protocol badge, mailbox, host and port, department, priority and CC count
The route list. The switch in the first column activates and deactivates a route without opening it.

Press New route and pick a Protocol — the form then shows only the fields that protocol needs, grouped as Source, Routing and Post-processing.

The email route modal with Source, Routing and Post-processing sections
The route form. Changing the protocol reshapes it.

Source — IMAP and POP3 #

Field What it does
Protocol IMAP, POP3 or Microsoft 365 (Graph).
Username / Email Address The mailbox login — the label changes to Email Address for Microsoft 365. Required for every protocol.
Host Mail server hostname, e.g. mail.yourdomain.com. Required for IMAP and POP3.
Port Required for IMAP and POP3. The usual values are 993 for IMAP over SSL, 143 for IMAP with STARTTLS, 995 for POP3 over SSL and 110 for POP3 with STLS.
Encryption SSL (encrypted from the first byte), TLS (connect in the clear, then upgrade) or None. None is not offered for POP3.
Password Stored encrypted and never displayed again. Leave blank when editing to keep the current password.

Warning: A POP3 route set to None is rejected — it would put the mailbox password on the wire in the clear — and RackHelm aborts rather than falling back to plaintext if a TLS upgrade is declined. Certificates are validated on both protocols, so a self-signed certificate on your mail server will fail the connection.

Source — Microsoft 365 #

Register an application in Azure AD and grant it the Mail.ReadWrite and Mail.Send application permissions (not delegated). Then put the mailbox address in Username and fill in Client ID, Tenant ID and Client Secret; the secret is stored encrypted, and a blank field on an edit keeps the existing one. Host, port, encryption and password are cleared automatically when you save a Graph route, and the Graph fields are cleared if you switch a route back to IMAP.

Routing #

Field What it does
Department Required. Every ticket from this mailbox lands here, quarantined ones included.
Priority Low, Medium or High — the priority given to new tickets from this mailbox.
Allowed senders Who may open a new ticket from this mailbox. Registered users only discards mail from addresses with no account. Guests only discards mail from registered customer accounts. Any takes both, creating a guest account for an unknown sender. Replies to an existing ticket are always taken from its requester and the addresses copied on it, whatever this is set to.
CC a copy to Comma-separated addresses. Each new ticket or reply filed from this mailbox is forwarded to them, with the subject Fwd: … and a link to the ticket. Mail from a sender the mail server could not verify, spam, bounces and automatic replies are not forwarded, and nor are copies to your own route mailboxes.
Route active Only active routes are polled.

Post-processing #

A message left in the inbox is imported again on the next poll, creating duplicate tickets. Choose Delete email, or Move to folder and name a folder. The folder is created if it does not exist, on IMAP and on Microsoft 365 alike.

A message that cannot be filed because something went wrong while reading it is never deleted. On IMAP and Microsoft 365 it is moved to a folder named RackHelm-Failed, created at the top of the mailbox the first time it is needed, so a person can look at it and it is not read again on every poll. Move it back to the inbox once the cause is fixed and the next poll files it.

Note: POP3 has no folders, so this section is hidden for POP3 routes and imported messages are deleted from the server. The exception is a message that could not be filed: it is left on the server and not read again for seven days. Bear that in mind if something else reads the same mailbox.

Scheduling the fetch #

Polling is driven by a scheduled job called Email to Tickets, listed under Schedules in the admin sidebar (/admin/system-schedules, requires manage_schedules). It ships disabled, so enable it. The seeded schedule is */5 * * * * — every five minutes, UTC. While you are setting a route up, switch on Enable File Logging on the schedule: it writes a running commentary of every connection, message and decision to the application log, which is by far the fastest way to diagnose a route.

The Email to Tickets entry on the System Schedules screen showing its cron fields and enabled switch
The job polls every active route on each run. One schedule covers all your mailboxes.

Note: The schedule only fires if the server’s cron is running Laravel’s scheduler, and the job itself is queued, so a queue worker must be running too. If both are missing, the route list will look perfectly healthy while nothing is ever fetched. To check them, open Platform Settings → System Info (/admin/system-info, which needs the View System Info permission): its Scheduler and workers card shows the scheduler’s last tick and whether Horizon is running, and the checks at the top of the page flag either one that has stopped (see System Info). Schedules → Queue Monitor also says “No active supervisors found. Is Horizon running?” when the queue worker is down.

Checking a route: Health and Test #

The Health column of the route list shows what the last poll found:

  • OK, with when it was last polled and, where different, its last success.
  • Failing, with when the error happened and when the route last worked, or “never”.
  • Never polled, for a route the schedule has not reached yet.

Under it, Last error opens the full text of the most recent error, which stays readable after a later poll succeeds, because a message moved to RackHelm-Failed is still waiting for someone. N not filed lists the messages the last poll handled without filing them, with the reason for each: on the spam list, a bounce, an automatic reply, a sender this route does not take, and so on.

The Test button signs in to the mailbox with the saved settings and reports what it found, for example “Signed in to mail.example.com as support@example.com: 3 messages waiting.” Nothing is read, moved or deleted, so it is safe to press at any time. Save the route first: the test always uses what is stored.

What happens to each message #

  1. Spam check. If the From address, or its whole domain, is on the blocklist, the message is dropped without becoming a ticket. It is still deleted or moved by the post-processing step. See The spam filter.
  2. Bounces and automatic replies. A delivery failure or an out-of-office reply never opens a ticket or reopens one. See Bounces and automatic replies below.
  3. Threading. RackHelm looks for the ticket the message answers, first by the message ids in its headers and then by the ticket number in its subject. If it finds one, the message is treated as a reply. See below.
  4. Sender authentication. See below. Mail that cannot be vouched for is quarantined rather than attributed to a customer.
  5. New ticket, or reply. A new ticket takes the route’s department and priority and opens as Open; a reply is appended to the existing thread, and reopens it if it was closed. Attachments are saved subject to the limits in Ticket attachments. Other machine-sent mail, such as a registry’s notice, still becomes a ticket, but gets no receipt and no autoresponder.
  6. Post-processing deletes or moves the message.

How a reply is threaded back onto a ticket #

Every ticket email RackHelm sends carries the ticket in its headers: a Message-ID of its own, and In-Reply-To and References pointing at the ticket’s thread. Mail clients copy those into a reply, so a reply finds its ticket even when the customer has edited the subject or you have changed the ticket prefix since. Replies to a ticket that has since been merged are filed on the ticket it was merged into.

When the headers name no ticket, the subject is searched: for # followed by your current prefix and a number, then for the wording of RackHelm’s own subjects (“Ticket #…”, “Support Ticket Created: #…”, and so on) with any prefix in front of the number, so a reply to an email sent under an earlier prefix still threads.

Each ticket email also has a Reply-To address: the mailbox of the active route for the ticket’s department, or else the first active route, or else the support email in Ticket Settings → General. A customer’s reply therefore lands in a mailbox RackHelm actually polls, even when your outgoing mail is sent from an address nobody reads.

Finding the ticket only says which ticket the sender means. Two further checks then decide whether the mail is a reply. The From address must belong to someone who may answer the ticket, case-insensitively: its owner, the sub-account that opened it, an address on its CC list, or a member of staff. And sender authentication must pass. Ticket numbers are sequential and printed in every notification, so ownership cannot rest on a forgeable From header alone.

  • Someone else. Mail from any other address is logged as “Reply denied: … does not own Ticket … and is not copied on it; filing it as a new ticket.” and opens a new ticket of its own, under the route’s usual sender rules. Nobody on the original ticket is copied on it.
  • Someone on the CC list. Their reply joins the thread in their own name.
  • A member of staff. Staff who answer a copy of a customer email by email are not writing to the customer. What they wrote is kept on the ticket as their internal note, headed “Emailed in by …, in reply to a copy of a customer email. It was NOT sent to the customer: reply from this page to answer them.”
  • An internal ticket. Nobody outside is ever emailed about one, so mail naming it opens a new ticket instead.

What is kept from a reply #

Every ticket email a customer can answer starts with the line ##- Please type your reply above this line -##. RackHelm keeps only what was typed above it, and cuts any other quoted history it recognises, so the ticket shows the customer’s new text rather than a growing copy of the whole conversation. When more than 200 characters were cut, the untrimmed email is kept on the message as an attachment, original-message.html, in case something that mattered was below the line.

A reply whose sender cannot be authenticated is logged as “Reply denied: sender authentication failed for … on Ticket #…” and then quarantined as its own ticket rather than discarded, so a genuine customer behind a mail server that stamps nothing does not simply vanish — they just cannot write into somebody else’s thread.

Note: Mail sent before 2.0.0 carries no RackHelm message ids, so a reply to one of those old emails threads by its subject alone, as it always did.

Addresses copied on a new email ticket #

When a new ticket is opened by an email addressed to one of your route mailboxes, the other addresses in its To and Cc lines (not yours, and not the sender’s) become the ticket’s CC list, up to ten. They are copied on the emails staff send about the ticket, though not on the automatic receipt, and they can reply onto it. Staff manage the list on the ticket page; see Working a ticket.

Bounces and automatic replies #

  • A bounce of one of your ticket emails is recognised by the RackHelm message ids it carries, and becomes a note on that ticket: “Delivery failure: …”, so staff know the customer may not have received it. A bounce that names no ticket is only listed under the route’s not filed messages.
  • An out-of-office or other automatic reply from the ticket’s owner or from someone copied on it, whose sender authentication passes, becomes a note “Automatic reply from …: …”. It does not reopen the ticket or alert anyone. Any other automatic reply is only listed under not filed.

These notes have no author: the ticket page shows them as Mail system, marked as an internal note that the customer cannot see. Nothing is ever sent back to a bounce or an automatic reply.

Guest accounts created from mail #

On a route that accepts unregistered senders, an unknown address gets a guest account. It is named from the sender’s From display name, split on the first space into first and last name, falling back to the local part of the address when the client sends no display name. The display name is attacker-controlled text, so it is scrubbed of invalid UTF-8, bidi overrides, zero-width characters, control characters and line separators, and capped at 255 characters — a strict MySQL install rejects the row otherwise, and the whole ticket is lost with it. See Guest tickets and the contact form.

Sender authentication #

Because a From header is trivial to forge, RackHelm will not bind an inbound message to a customer account on the strength of it. On an IMAP or POP3 route it reads the Authentication-Results header your own mail server stamps, and trusts only a header bearing your server’s authserv-id — the token before the first semicolon, typically the MX hostname. Two settings govern this; neither has a field in the admin UI.

Setting Effect
inbound_mail_trusted_authserv_id
(MAIL_TRUSTED_AUTHSERV_ID in .env)
Your MTA’s authserv-id, e.g. mx.example.com. Required for IMAP and POP3 routes. While it is unset, no message on those routes can be authenticated.
inbound_mail_require_authentication
(MAIL_REQUIRE_AUTHENTICATED_SENDER in .env)
What to do when a message cannot be authenticated: quarantine it, or accept it on the From header alone. Defaults to quarantine.

Only the topmost header stamped by your own authserv-id is read, and only that one — any further copies are the sender’s own and are ignored. With no authserv-id configured, RackHelm logs “No trusted authserv-id configured (setting ‘inbound_mail_trusted_authserv_id’); treating mail from … as unauthenticated. Configure it to enable sender authentication.” and treats the message as unauthenticated. It does not fall back to the topmost header of any kind: on a plain Postfix that stamps nothing, the only header present would be the sender’s own forged one, which is exactly the spoof this check exists to stop.

Warning: inbound_mail_require_authentication now fails closed. An unset or blank setting falls back to the mail.require_authenticated_sender default, which is true, so an install that has never saved the value quarantines unauthenticated mail rather than accepting it. Only an explicit boolean — 0 or false — turns the check off, and only do that if your MTA genuinely cannot stamp Authentication-Results, understanding that it restores the ability to spoof any sender. This is the reverse of the behaviour in 1.0.0.x, where an unsaved setting read as off.

Microsoft 365 (Graph) routes are judged differently #

Mail read over Graph was received by Exchange Online, not by whatever MTA you run for your other routes, so your configured authserv-id is deliberately not used on a Graph route — no server that strips forged copies of that id ever handled the message, so a sender could stamp it themselves. Exchange Online Protection writes Authentication-Results with no authserv-id at all, which is why the trusted-id lookup could never find its header and why, when sender authentication was first switched on, every single Graph message ended up quarantined.

Two properties of Exchange stand in for the missing id:

  • Exactly one X-MS-Exchange-Organization-AuthAs header, reading Anonymous. The header firewall strips X-MS-Exchange-Organization-* from mail arriving from outside the organisation and transport stamps its own, so a single Anonymous means the message came in from the internet through EOP — which stamps an Authentication-Results verdict on every such message. Internal and connector-relayed mail carries no EOP verdict and is not trusted here, logged as “Mail from … did not arrive anonymously from the internet (X-MS-Exchange-Organization-AuthAs: …), so it carries no Exchange Online Protection verdict to trust.”
  • Every Authentication-Results header on the message must pass. A sender can add headers of their own but cannot remove the one EOP stamped, so a forged dmarc=pass can never outvote the genuine verdict wherever Exchange happens to place it.

Microsoft 365 quarantine notices #

Exchange Online generates its own “You have messages in quarantine” digests inside the tenant, so they never pass through EOP and carry no Authentication-Results to judge. Every one of them used to be filed as an unverified sender.

RackHelm now recognises them and accepts them as genuine. The test is narrow on purpose: the message must be on a Graph route, the From address must be exactly quarantine@messaging.microsoft.com, and Exchange must have stamped exactly one X-MS-Exchange-Organization-AuthAs: Internal and exactly one X-MS-Exchange-Organization-AuthMechanism: 10 — headers a sender on the internet cannot supply, because the header firewall strips them. Other internal mail, such as a mailbox user’s own submissions (AuthMechanism 04), still has to authenticate normally. The acceptance is logged as “Mail from … is a Microsoft 365 quarantine notice generated inside the tenant; accepting it on Exchange’s own AuthAs/AuthMechanism stamp.”

Note: A quarantine notice becomes an ordinary ticket in the route’s department, but nothing is emailed back: neither the “Support Ticket Created” acknowledgement nor the route’s autoresponder is sent. Acknowledging one would only mail Microsoft’s unattended address every day.

Quarantined mail #

A message that fails authentication, on a route that requires it, still becomes a ticket you can read — but it is not attributed to anyone. Its subject is prefixed [UNVERIFIED SENDER] and truncated to 250 characters, it is owned by a disabled placeholder account (unverified-sender@unverified.invalid) so it can never surface in a real customer’s portal, it lands in the route’s department at the route’s priority, and no autoresponder is sent back at that possibly forged address. Its activity log records the address the message claimed to be from: “Inbound mail claimed to be from … , but the receiving mail server did not confirm SPF/DKIM/DMARC for it. The ticket is not attributed to that address and no autoresponder was sent.” The quarantine itself is logged as “Quarantined unauthenticated mail claiming to be from … as ticket #…”.

On a route set to Registered users only, unauthenticated mail from an address with no account is discarded outright instead, logged as “Unauthenticated mail from … discarded: this route only accepts registered users.” Unauthenticated mail claiming to be a registered customer is always kept — those are the impersonation attempts staff need to see.

Warning: If the address unverified-sender@unverified.invalid is ever held by a real, enabled account, RackHelm refuses to file quarantined mail against it — “The unverified-sender placeholder address is held by a real account; refusing to file quarantined mail against it.” — and the message is lost. Never create or enable an account on that address; if you find one, it was planted to read other people’s quarantined mail.

Note: Two more behaviours have no field on the form. A route can carry an autoresponder template that is emailed back to the sender when a new ticket is created, but there is nowhere to select one in the current build.

Troubleshooting #

Symptom Cause and fix
No tickets at all, no log entries The Email to Tickets schedule is disabled, or the scheduler cron / queue worker is not running. On installs made before 2.0.3, the queue worker (Horizon) stopped for good the first time the server or its process supervisor restarted; on Ubuntu the automatic security updates restart supervisor without a reboot. Run sudo supervisorctl start rackhelm-horizon to get the queue moving, and update to 2.0.3, which corrects the setting. See Queue workers, Horizon and the scheduler.
“IMAP Connection Failed” in the log Host, port, encryption or credentials are wrong, or the certificate does not validate. Certificate checking cannot be turned off.
“POP3 STLS refused” or “POP3 TLS negotiation failed” The server does not support STLS on that port. Use SSL on 995 instead.
Every message on an IMAP or POP3 route becomes an [UNVERIFIED SENDER] ticket inbound_mail_trusted_authserv_id is unset or does not match what your MTA stamps, and requiring authentication is on by default. Read a raw message’s Authentication-Results header and copy the token before the first semicolon.
“No trusted authserv-id configured …” in the log Same cause. The setting is empty and no message on that route can be authenticated.
“No Authentication-Results header stamped by ‘…’ on mail from …” The id is set but does not match. Compare it against a raw message, character for character; the comparison is case-insensitive but otherwise exact.
Mail on a Graph route is quarantined although SPF and DMARC pass Check X-MS-Exchange-Organization-AuthAs. Anything other than a single Anonymous — internal mail, or mail relayed in over a connector — carries no EOP verdict to trust.
Replies open new tickets instead of threading The customer replied from an address that is not the ticket’s owner, the sub-account that opened it or on its CC list; the log says “Reply denied: … does not own Ticket …”. Or their mail client dropped both the message-id headers and the ticket number in the subject. Add the address to the ticket’s CC list, or merge the new ticket into the old one.
The Health column says Failing Open Last error for the reason, and press Test to check the sign-in with the saved settings. A wrong password, host or certificate fails the test as well as the poll.
A RackHelm-Failed folder has appeared in the mailbox A message could not be filed. Read Last error on the route, fix the cause, and move the message back to the inbox to have it filed on the next poll.
A customer’s reply shows only part of what they wrote Text below the reply line, or that looked like quoted history, was cut. Open original-message.html on the message to see the whole email.
The same email arrives as a ticket repeatedly Post-processing is failing. Check the log for “IMAP Action Failed” and confirm the account may delete or create folders.
Mail from unknown addresses vanishes silently The route is set to Registered users only.
A mailbox stopped importing after a password change Edit the route and enter the new password; a blank field keeps the old one.
Microsoft 365 route returns nothing The Azure app is missing Mail.ReadWrite/Mail.Send as application permissions, or admin consent has not been granted.