How to fix Swoosh error
April 2023 • 109 words • 1 min read
Swoosh is the default email library in Phoenix. It requires an adapter (like AWS SES) and a couple of extra libraries to work properly.
For example, if you are using (AmazonSES adapter)[https://hexdocs.pm/swoosh/Swoosh.Adapters.AmazonSES.html], then you will need to add (gen_smtp)[https://hex.pm/packages/gen_smtp] library as a dependency
# if your mix.exs add this inside defp deps function
{:gen_smtp, "~> 1.2"}
You will also need to set SES specific environment variables and update your config.exs file
config :example_app, ExampleApp.Mailer,
adapter: Swoosh.Adapters.AmazonSES,
region: System.get_env("AWS_SES_SMTP_REGION_ENDPOINT"),
access_key: System.get_env("AWS_ACCESS_KEY"),
secret: System.get_env("AWS_SECRET_ACCESS_KEY")
You might still see the following error:
** (UndefinedFunctionError) function false.post/4 is undefined (module false is not available)
This is because Swoosh needs an API client to send email. In dev.exs it is set to false and you will have to enable it. Swoosh supports both Hackney and Finch out of box. And you will have to add any one of them as dependency in your mix.exs
file.
In my app, I was using Finch. In my application.ex
file Finch was started with the name ExampleApp.Finch
- therefore, I had to also provide the finch_name
as a configuration parameter.
config :swoosh, api_client: Swoosh.ApiClient.Finch, finch_name: ExampleApp.Finch