{"id":24321992,"url":"https://github.com/malomohq/detour","last_synced_at":"2026-03-14T09:39:26.060Z","repository":{"id":57489768,"uuid":"239582034","full_name":"malomohq/detour","owner":"malomohq","description":"Easily test email deliverability using simple-to-use assertions against a real SMTP server","archived":false,"fork":false,"pushed_at":"2021-08-24T19:16:37.000Z","size":25,"stargazers_count":5,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-12T02:03:22.981Z","etag":null,"topics":["elixir-lang","email","made-by-malomo","smtp","testing"],"latest_commit_sha":null,"homepage":"","language":"Elixir","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/malomohq.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-02-10T18:24:15.000Z","updated_at":"2024-03-02T02:06:02.000Z","dependencies_parsed_at":"2022-08-29T14:11:28.035Z","dependency_job_id":null,"html_url":"https://github.com/malomohq/detour","commit_stats":null,"previous_names":["malomohq/detour-elixir"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/malomohq/detour","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Fdetour","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Fdetour/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Fdetour/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Fdetour/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/malomohq","download_url":"https://codeload.github.com/malomohq/detour/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/malomohq%2Fdetour/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269352025,"owners_count":24402705,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["elixir-lang","email","made-by-malomo","smtp","testing"],"created_at":"2025-01-17T17:36:43.245Z","updated_at":"2025-12-11T23:48:26.454Z","avatar_url":"https://github.com/malomohq.png","language":"Elixir","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Detour\n\nDetour provides the ability to easily test email deliverability using\nsimple-to-use assertions against a real SMTP server.\n\n## Installation\n\nAdd `detour` to your list of dependencies in `mix.exs`:\n\n```elixir\ndef deps do\n  [{:detour, \"~\u003e 0.2\", only: :test}]\nend\n```\n\n## Usage\n\nEnsure `detour` is started before running any tests.\n\n```elixir\nExUnit.start()\n\nApplication.ensure_all_started(:detour)\n```\n\n\n### Starting a Detour Server\n\n`Detour.open/1` can be used to start a Detour server. A Detour server is an\nin-memory SMTP server that can be used to receive SMTP traffic and perform\nassertions to verify behavior.\n\n`Detour.open/1` returns a `%Detour{}` struct with fields `pid` and `port`. `pid`\nis the address of the Detour server and `port` is the port number used when\nsending traffic to Detour. The relay used by your SMTP client should always be\n`localhost` when sending traffic to a Detour server.\n\nBy default, `Detour.open/1` will choose an open port. This is preferable over\nspecifying a static port as it makes working with Detour more flexible. You can\nspecify a port by passing the `:port` option to `Detour.open/1`.\n\nWhen allowing Detour to provide a port Detour will take take care of releasing\nthe port after a test finishes. If you specify a port you will need to perform\nthis clean up yourself. You can do this by calling `Detour.shutdown/2` after a\ntest has run.\n\n#### Examples\n\nWhen allowing Detour to provide a port.\n\n```elixir\ntest \"automatic port assignment\" do\n  detour = Detour.open()\n\n  from = \"me@notyou.com\"\n\n  to = [\"you@notme.com\"]\n\n  body = \"To: you@notme.com\\r\\nSubject: Hello, world!\\r\\nFrom: me@notyou.com\\r\\nContent-Type: text/plain\\r\\nContent-Transfer-Encoding: quoted-printable\\r\\n\\r\\nNice to meet you\"\n\n  message = {from, to, body}\n\n  :gen_smtp_client.send_blocking(message, [address: \"localhost\", port: detour.port])\n\n  assert_message_delivered message\nend\n```\n\nWhen providing a port to Detour.\n\n```elixir\ntest \"specifying a port\" do\n  detour = Detour.open([port: 2525])\n\n  from = \"me@notyou.com\"\n\n  to = [\"you@notme.com\"]\n\n  body = \"To: you@notme.com\\r\\nSubject: Hello, world!\\r\\nFrom: me@notyou.com\\r\\nContent-Type: text/plain\\r\\nContent-Transfer-Encoding: quoted-printable\\r\\n\\r\\nNice to meet you\"\n\n  message = {from, to, body}\n\n  :gen_smtp_client.send_blocking(message, [address: \"localhost\", port: detour.port])\n\n  assert_message_delivered message\n\n  Detour.shutdown(detour)\nend\n```\n\n### Message Format\n\nMessages are expected to be in the format `{from, [to], body}`. `from`, `to` and\n`body` are all string values. `body` will be the raw text your SMTP client sends\nto Detour. This will typically be an RFC2822 encoded string. If your email\nlibrary doesn't provide facilities to parse a message body you can use the\n[`mail`](https://hex.pm/packages/mail) package.\n\n#### Example\n\n```elixir\ndef test \"rfc2822 messages\" do\n  detour = Detour.open()\n\n  from = \"me@notyou.com\"\n\n  to = [\"you@notme.com\"]\n\n  message =\n    Mail.build()\n    |\u003e Mail.put_from(from)\n    |\u003e Mail.put_to(to)\n    |\u003e Mail.put_subject(\"Hello, world!\")\n    |\u003e Mail.put_text(\"Nice to meet you\")\n\n  body = Mail.render(message)\n\n  message = {from, to, body}\n\n  :gen_smtp_client.send_blocking(message, [address: \"localhost\", port: detour.port])\n\n  assert_message_delivered message\nend\n```\n\n### Assertions\n\n#### `assert_message_delivered/3`\n\nEnsure a message has successfully been sent.\n\n```elixir\ntest \"a message has been delivered\" do\n  detour = Detour.open()\n\n  from = \"me@notyou.com\"\n\n  to = [\"you@notme.com\"]\n\n  body = \"To: you@notme.com\\r\\nSubject: Hello, world!\\r\\nFrom: me@notyou.com\\r\\nContent-Type: text/plain\\r\\nContent-Transfer-Encoding: quoted-printable\\r\\n\\r\\nNice to meet you\"\n\n  message = {from, to, body}\n\n  :gen_smtp_client.send_blocking(message, [address: \"localhost\", port: detour.port])\n\n  assert_message_delivered message\nend\n```\n\n#### `refute_message_delivered/3`\n\nEnsure a message has not been sent.\n\n```elixir\ntest \"a message has not been delivered\" do\n  detour = Detour.open()\n\n  from = \"me@notyou.com\"\n\n  to = [\"you@notme.com\"]\n\n  body = \"To: you@notme.com\\r\\nSubject: Hello, world!\\r\\nFrom: me@notyou.com\\r\\nContent-Type: text/plain\\r\\nContent-Transfer-Encoding: quoted-printable\\r\\n\\r\\nNice to meet you\"\n\n  message = {from, to, body}\n\n  :gen_smtp_client.send_blocking({\"we@us.com\", to, body}, [address: \"localhost\", port: detour.port])\n\n  refute_message_delivered message\nend\n```\n\n#### `assert_number_of_messages_delivered/3`\n\nEnsure the expected number of messages has been delivered.\n\n```elixir\ntest \"the expected number of messages have been delivered\" do\n  detour = Detour.open()\n\n  from = \"me@notyou.com\"\n\n  to = [\"you@notme.com\"]\n\n  body = \"To: you@notme.com\\r\\nSubject: Hello, world!\\r\\nFrom: me@notyou.com\\r\\nContent-Type: text/plain\\r\\nContent-Transfer-Encoding: quoted-printable\\r\\n\\r\\nNice to meet you\"\n\n  message = {from, to, body}\n\n  :gen_smtp_client.send_blocking(message, [address: \"localhost\", port: detour.port])\n  :gen_smtp_client.send_blocking(message, [address: \"localhost\", port: detour.port])\n\n  assert_number_of_messages_delivered 2\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalomohq%2Fdetour","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmalomohq%2Fdetour","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmalomohq%2Fdetour/lists"}