Need pointers on how to configure email notification when using phx.gen.auth

If you don’t already know about the /dev/mailbox route that is built-in, that’s worth knowing about. Phoenix simulates an email server out of the box so you can just go to the localhost:4000/dev/mailbox URL in your server whenever your server “sends” an email, and go from there. This is due to the behavior of the default Swoosh (the module that sends email) adapter, which is set to use the Local adapter.

Out of the box, phx.gen.auth does the following IIRC:

  • Adds a confirmed_at attribute for each user, which is nil by default
  • Sends a confirmation email to the user containing a confirmation URL during registration (which will, of course, confirm their email address). There is also a built-in route that can be used for the user to request a new confirmation email.
  • When that email is opened, it confirms that user by setting the user’s confirmed_at attribute to the current data

Here’s a commit I made that sets up email sending via Amazon SES (in the commit, I it configured to send in dev so I could make sure it works, you’ll probably just want to use the default Local adapter in dev most of the time so that you can just go to /dev/mailbox):

Swoosh has adapters for different services (like Amazone SES). I believe Postmark is a great email provider with a good-enough free tier (at least that’s what I recall from when I last looked into it).

2 Likes