function false.post/4 is undefined: Swoosh Mailgun fix
This error means Swoosh's :api_client setting is false, so the Mailgun adapter ends up calling false.post/4. Set it to Swoosh.ApiClient.Finch with a running Finch process, or to Hackney, then fully restart the app. Below: where the false usually comes from, working config, and how to verify.
Sohail Hussain8 min readShort answer
- The error means Swoosh's :api_client setting is false, so the Mailgun adapter tried to call post/4 on a module named false instead of an HTTP client.
- Set the :swoosh api_client option to Swoosh.ApiClient.Finch (with a Finch process running) or Swoosh.ApiClient.Hackney in the environment where you use Mailgun, then fully restart the app.
- The request never reached Mailgun, so your API key and domain have not been tested yet.
You switched a Phoenix or plain Elixir app to the Mailgun adapter, tried to send, and got this:
(UndefinedFunctionError) function false.post/4 is undefined (module false is not available)
This page explains where the false comes from, how to replace it with a working HTTP client, and what usually fails next.
Why it happens
Swoosh's HTTP-based adapters, Mailgun included, do not make HTTP requests themselves. They pass the request to whatever module is set as the API client. The call has four arguments (roughly URL, headers, body and the email), which is why the error says post/4.
If the client setting is false, Elixir evaluates a call on a module called false. No such module exists, so you get UndefinedFunctionError. This is a local configuration problem. Mailgun was never contacted.
The causes, most common first:
- A leftover
falsefrom a generated config file. Phoenix generators typically writeconfig :swoosh, :api_client, falseinto the dev and test environments, because the local and test adapters need no HTTP. If you point dev at Mailgun to try real delivery, thefalseis still there. - Config load order. Files load in this order:
config/config.exs, the environment file it imports, thenconfig/runtime.exs. The last value wins, so afalsein an environment file overrides a good value inconfig.exs. - The client is set, but the app was not restarted. Swoosh config is read at boot, so a running node keeps the old value.
- No client dependency in
mix.exs. This usually gives a different error oncefalseis gone, but it is worth checking while you are in there.
A thread on the Elixir Forum reports this exact symptom with the Mailgun adapter. The thread does not show a confirmed fix, so the steps below come from how Swoosh dispatches requests. Check them against the Swoosh version in your mix.lock.
Step-by-step fixes
Fix 1: find the false and replace it
-
Search your config for the setting:
grep -rn "api_client" config/ -
Look for a line like this in the environment you are running:
config :swoosh, :api_client, false -
Replace it with a real client. Finch is the usual choice in a recent Phoenix app:
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: MyApp.Finch -
Make sure the Mailgun adapter is configured for the same environment:
# config/runtime.exs config :my_app, MyApp.Mailer, adapter: Swoosh.Adapters.Mailgun, api_key: System.fetch_env!("MAILGUN_API_KEY"), domain: System.fetch_env!("MAILGUN_DOMAIN") -
Replace
MyAppandmy_appwith your application's names. -
Stop the app and start it again (
mix phx.serveroriex -S mix). Recompiling alone is not enough.
Restart, do not just recompile
Swoosh config is read at boot. A running node or an open IEx session keeps the old false value even after you edit the file.
Fix 2: start Finch in your supervision tree
Setting Swoosh.ApiClient.Finch without a running Finch process fails later with a different error. Add Finch to the children list in lib/my_app/application.ex:
children = [
{Finch, name: MyApp.Finch},
# ...the rest of your children
]
The finch_name in the Swoosh config must match this name. If your app already starts a Finch for other purposes, reuse its name instead of starting a second one. If :finch is not in your mix.exs deps, add it and run mix deps.get.
Fix 3: use Hackney instead
If you prefer Hackney, set it as the client and add the dependency:
config :swoosh, :api_client, Swoosh.ApiClient.Hackney
# mix.exs
{:hackney, "~> 1.9"}
Run mix deps.get and restart. Newer Swoosh releases also ship other clients, such as one based on Req. Check the Swoosh docs on HexDocs for what your installed version supports. For a Phoenix app I'd pick Finch, since it is usually already in the project.
Fix 4: confirm the setting took effect
In iex -S mix, run:
Application.get_env(:swoosh, :api_client)
You want a module name such as Swoosh.ApiClient.Finch, not false. Then check the mailer:
Application.get_env(:my_app, MyApp.Mailer)
It should show Swoosh.Adapters.Mailgun with your api_key and domain. If :api_client still returns false, a later config file is overriding your change. Run the grep again and look at runtime.exs too.
Cause, symptom and fix at a glance
| Cause | What you see | Fix |
|---|---|---|
api_client is false in the active env | false.post/4 is undefined | Set Finch or Hackney (Fix 1) |
Client set in config.exs, false in dev.exs | Same error in dev only | Remove or change the later false |
| Finch configured but not started | A different error about the Finch name or pool | Add {Finch, name: MyApp.Finch} (Fix 2) |
| Config edited, app not restarted | Same error as before | Full restart |
Errors you may hit next
Once the client works, the request reaches Mailgun. Problems then come back as HTTP responses instead of a crash.
| What you see | Likely cause |
|---|---|
| 401 Unauthorized | Wrong or missing api_key |
| 404 or "domain not found" | Wrong domain, or the domain lives in another Mailgun region |
| 400 about the sender | from address not on your verified Mailgun domain |
| Accepted but lands in spam | Domain DNS not set up; see how to set up SPF, DKIM and DMARC |
Region mismatches are the one people trip over most. Mailgun's help center lists separate API base URLs for the US, EU and AU regions, so a domain created in the EU region will not work against the US host. Swoosh's Mailgun adapter has a base_url option for this; check the adapter's docs for the exact value format. Mailgun's own overview of how to start sending email also notes that production sending needs a domain set up and verified through DNS.
Keep dev on the local adapter
Leave dev and test on the local and test adapters, where false is correct, and try Mailgun in a staging environment. That way nobody flips the client setting back and forth.
Checklist before you try again
grep -rn "api_client" config/shows nofalsefor the environment you are running.- The client dependency (
:finchor:hackney) is inmix.exsandmix deps.gethas run. - The
finch_namein config matches the name started inapplication.ex. - The mailer config uses
Swoosh.Adapters.Mailgunwithapi_keyanddomainset. - You stopped and restarted the app after the last config change.
Application.get_env(:swoosh, :api_client)in IEx returns a module, notfalse.
If nothing works
Swoosh is an open-source library, so the best place to ask is the Swoosh issue tracker or the Elixir Forum thread on this error. For delivery problems after the client works, contact Mailgun support. Include:
- the full stack trace, not just the first line
- your Swoosh and Elixir versions from
mix.lock - the
config/files involved, with the API key removed - the output of the two
Application.get_envchecks above
Subject: Swoosh Mailgun adapter raises UndefinedFunctionError false.post/4
Hi,
Sending with Swoosh.Adapters.Mailgun raises:
(UndefinedFunctionError) function false.post/4 is undefined (module false is not available)
Swoosh version: {version from mix.lock}
Elixir/OTP: {versions}
Environment: {dev/test/prod}
Application.get_env(:swoosh, :api_client) returns: {value}
I already tried: setting :api_client to Swoosh.ApiClient.Finch, starting Finch
in the supervision tree, and fully restarting the app.
Full stack trace and sanitized config are attached.
Common questions
Why does Phoenix set api_client to false at all?
The default dev and test adapters, Swoosh.Adapters.Local and Swoosh.Adapters.Test, do not send HTTP requests, so they need no client. Setting it to false is harmless until you switch to an HTTP adapter like Mailgun.
Can I use the Mailgun SMTP adapter instead and skip the HTTP client?
Swoosh has an SMTP adapter that does not use an HTTP API client, so the error would not apply. You would then use Mailgun's SMTP credentials instead of the API key. Check the Swoosh docs for the extra dependency that adapter needs.
Did Mailgun reject my request?
No. The error is raised inside your app before any network call, so Mailgun never saw the request and its logs will show nothing for this attempt.
Do I need the client setting in every environment?
Only in environments that use an HTTP adapter. Production using Mailgun needs a real client; dev and test can keep false while they use the local and test adapters.
Explore: Email Marketing Strategy
Related Articles
414 Request-URI Too Large in n8n's Amazon SES node: fix
The error 414 Request-URI Too Large in n8n's AWS SES node means a server in the path refused a request whose URL was too long, which a long HTML body can cause when it travels in the URL. Send through the SES v2 API with an HTTP Request node, or use SES SMTP.
Access denied, bad outbound sender: Outlook cold email fix
"Access denied, bad outbound sender" (550 5.1.8) means Microsoft 365 has put your mailbox on its restricted users list for spam-like sending. An admin must unblock it under Restricted entities in the Microsoft Defender portal. Then clean your list, lower your volume and resume gradually.
Acoustic Campaign "Application error" on login: bookmark fix
Acoustic Campaign shows "application error" at login when you open it from a bookmark saved while you were logged in, because the bookmark carries the old session. Log out, type your pod URL (campaign-us-[X].goacoustic.com) into the address bar, log in, then save a fresh bookmark.
ActiveCampaign 502 Bad Gateway and Tags Failed to Load: Fixes
"Bad gateway Error code 502" in ActiveCampaign means Cloudflare, the proxy in front of the app, got no valid response from ActiveCampaign's servers. That is usually their side. Check the status page, retry in a clean browser session, clear cookies, then send support the Ray ID if it persists.
Ready to supercharge your email marketing?
Start sending smarter emails with AI-powered campaigns. No credit card required.
Get Started Free