[
    {
        "role": "user",
        "content": "I%27m%20using%20exim%204.9%20and%20need%20to%20test%20routing%20of%20a%20username%20to%20see%20what%20is%20going%20wrong%20with%20delivery."
    },
    {
        "role": "assistant",
        "content": "If you're using Exim 4.9 and want to debug why delivery to a certain username (email address) is failing, there's a set of tools and techniques you can use to test routing and find out exactly what router and transport are involved. Here\u2019s a step-by-step guide to help you test and trace what\u2019s happening under the hood.\n\n---\n\n## 1. Use `exim -bt` to Test Routing\n\nThe quickest way to see how Exim would route an address is with:\n\n```\nexim -bt recipient@domain.tld\n```\n\nThis \u201caddress test\u201d mode shows which router will be used, and which transport will eventually deliver the message. ([support.cpanel.net](https://support.cpanel.net/hc/en-us/articles/360053412433-How-do-I-test-how-Exim-will-route-a-given-address?utm_source=openai))\n\nExample output might look like:\n\n```\nrecipient@domain.tld\n  router = local_user, transport = local_delivery\n```\n\nThis indicates which rule (\u201clocal_user\u201d) matches and what transport is used. If routing is wrong, you\u2019ll see a different router or a router decline. Use that as a clue. ([support.cpanel.net](https://support.cpanel.net/hc/en-us/articles/360053412433-How-do-I-test-how-Exim-will-route-a-given-address?utm_source=openai))\n\n---\n\n## 2. Use `exim -bv` or `exim -bvs`\n\nThese options verify if an address is accepted (routing\u2010wise) by the routers, without doing a full route or delivery. This is useful if Exim is rejecting the recipient (e.g. \u201cuser unknown\u201d). For example:\n\n```\nexim -bv recipient@domain.tld\n```\n\nor with sender verification too:\n\n```\nexim -bvs sender@domain.tld recipient@domain.tld\n```\n\nOutput will say whether at least one router \u201caccepts\u201d the address. ([exim.org](https://www.exim.org/exim-html-current/doc/html/spec_html/ch-how_exim_receives_and_delivers_mail.html?utm_source=openai))\n\n---\n\n## 3. Increase Verbosity, Use Debug Modes\n\nWhen routing looks correct but deliveries still fail, enable more debug output. You can combine verbose mode and debug switches:\n\n```\nexim -d+all -bt recipient@domain.tld\n```\n\n- The `-d+all` adds all debug categories. You can also use subsets, for example `-d+transport+lookup` to get more focused info. ([wiki.debian.org](https://wiki.debian.org/PkgExim4UserFAQ?utm_source=openai))  \n- The `-bt` to test routing but now with debugging, so you see preconditions, router evaluations, and why routers are skipped or chosen. ([exim.org](https://www.exim.org/exim-html-current/doc/html/spec_html/ch-how_exim_receives_and_delivers_mail.html?utm_source=openai))\n\n---\n\n## 4. Add `debug_print` in Routers\n\nIf you suspect a particular router is misbehaving (see from step 1 which router would match), add a `debug_print` line in that router block in your Exim config (often `/etc/exim4/exim.conf` or in the router files under `/etc/exim4/routers/`). For example:\n\n```\nmy_router:\n  driver = accept\n  condition = ...\n  transport = my_transport\n  debug_print = \"Checking my_router: local_part=$local_part domain=$domain\"\n```\n\nThen rerun the routing test with `-bt` or full debug. This will cause Exim to print the expanded debug_print message when evaluating that router. ([exim.org](https://www.exim.org/exim-html-current/doc/html/spec_html/ch-generic_options_for_routers.html?utm_source=openai))\n\n---\n\n## 5. Review Router Preconditions\n\nRemember routers in Exim have \u201cpreconditions\u201d that are evaluated before matching the address. Some of these are:\n\n- `domains`, `local_parts` etc.\n- `local_part_prefix` / `local_part_suffix`\n- `check_local_user` (checks whether local part is valid user on system)\n- `require_files`\n- `condition`\n\nIf any precondition fails, the router is skipped. Using debug print and debug mode will show you which precondition is failing. ([exim.org](https://www.exim.org/exim-html-current/doc/html/spec_html/ch-how_exim_receives_and_delivers_mail.html?utm_source=openai))\n\n---\n\n## 6. Simulate Message Delivery (Optional)\n\nIf the issue might be not just routing but transport or downstream delivery, you can simulate or force delivery:\n\n- Send a test message via exim command line with verbose mode:\n\n  ```\n  exim -v somebody@targetdomain.com\n  ```\n\n  Then write the message body manually or use standard input. You'll see connection attempts, MX lookups, which transport is used, etc. ([blog.betterwebtechnologies.com](https://blog.betterwebtechnologies.com/send-a-test-mail-via-exim-command-line/?utm_source=openai))\n\n- Review the queue: `exim -bp` to list queued messages. If messages are stuck or frozen, that\u2019s useful to know. ([linagora.com](https://linagora.com/en/technology/exim?utm_source=openai))\n\n---\n\n## 7. Log Files\n\nAlways check the Exim log files:\n\n- `mainlog` (or equivalent, often `/var/log/exim4/mainlog`) for delivery routes, accepted or bounced messages\n- `rejectlog` if recipients are being rejected\n- `paniclog` for severe internal errors\n\nWatch how Exim responds when you send a test message. The logs will show which router was matched, which transport, whether MX lookup failed, authentication issues, or permission/relay issues.\n\n---\n\n## Example Workflow\n\nPutting it all together, here\u2019s how you might debug delivery for **user@example.com**:\n\n1. Run:  \n   ```\n   exim -bt user@example.com\n   ```\n   \u2192 see which router/transport is selected (or none, if routing fails).\n\n2. If nothing plausible shows up, increase debug:  \n   ```\n   exim -d+all -bt user@example.com\n   ```\n   Examine why expected routers are skipped (due to precondition failures).\n\n3. Add a `debug_print` inside the candidate router(s) to display key variables, re-run test.\n\n4. If routing looks correct but delivery still fails, send a test message with verbose:  \n   ```\n   exim -v user@example.com\n   ```\n   \u2192 watch the MX resolution, SMTP commands, remote errors.\n\n5. Check log files after this attempt to see the real live result.\n\n---\n\nIf you like, I can help you walk through this with your specific username saying what you\u2019ve tried, show your router definitions (the ones related to that domain), and help pinpoint what\u2019s likely wrong. Would you prefer doing that?"
    }
]