https://github.com/resend/resend-phoenix-example
This example shows how to use Resend with Phoenix
https://github.com/resend/resend-phoenix-example
Last synced: about 1 year ago
JSON representation
This example shows how to use Resend with Phoenix
- Host: GitHub
- URL: https://github.com/resend/resend-phoenix-example
- Owner: resend
- License: mit
- Created: 2023-06-05T00:09:43.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2024-01-01T10:58:41.000Z (over 2 years ago)
- Last Synced: 2025-04-06T00:33:11.233Z (about 1 year ago)
- Language: Elixir
- Homepage: https://resend.com/docs/send-with-phoenix
- Size: 329 KB
- Stars: 6
- Watchers: 1
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Resend with Phoenix
This example shows how to use Resend with [Phoenix](https://phoenixframework.org/).
Created using Phoenix [v1.7.3](https://github.com/phoenixframework/phoenix/releases/tag/v1.7.3).
## Prerequisites
To get the most out of this guide, you’ll need to:
* [Create an API key](https://resend.com/api-keys)
* [Verify your domain](https://resend.com/domains)
## Setup
Add `:resend` to your project deps:
```elixir
defp deps do
[
{:resend, "~> 0.4"},
# ...
]
end
```
Once added, fetch the new dependency with `mix deps.get`.
Configure your `App.Mailer` to use the Resend Swoosh adapter by adding the following code
to [`config/runtime.exs`](./config/runtime.exs):
```elixir
config :app, App.Mailer,
adapter: Resend.Swoosh.Adapter,
api_key: System.get_env("RESEND_KEY") || "re_123456789"
```
Replace `re_123456789` with your own API key, or fetch it from the environment.
To start your Phoenix server:
* Run `mix setup` to install and setup dependencies
* Start Phoenix endpoint with `mix phx.server` or inside IEx with `iex -S mix phx.server`
Now you can visit [`localhost:4000`](http://localhost:4000) from your browser.
If running in `iex`, you can send an email by invoking this function, as an example:
```elixir
iex(1)> App.Users.UserNotifier.deliver_confirmation_instructions("recipient@example.com", "example.com")
```
Alternatively, try creating an account at [`localhost:4000/users/log_in`](http://localhost:4000) to
receive a welcome email.
See [`lib/app/users/user_notifier.ex`](./lib/app/users/user_notifier.ex) for other examples of delivering emails.
## Use with Phx.Gen.Auth
The above setup works as-is with code generated from [phx_gen_auth](https://hexdocs.pm/phoenix/mix_phx_gen_auth.html),
Phoenix Framework's built-in auth generator, as demonstrated in this example repo.
## Learn more
* Official website: https://www.phoenixframework.org/
* Guides: https://hexdocs.pm/phoenix/overview.html
* Docs: https://hexdocs.pm/phoenix
* Forum: https://elixirforum.com/c/phoenix-forum
* Source: https://github.com/phoenixframework/phoenix
## License
MIT License