πŸ“§
Emails
Open up email.ex and you will see a list of functions that generate Swoosh email structs. Eg:
1
def confirm_register_email(email, url) do
2
base_email()
3
|> to(email)
4
|> subject("Confirm instructions")
5
|> render_body("confirm_register_email.html", %{url: url})
6
|> premail()
7
end
Copied!
If I run this function in IEX I can see the Swoosh struct:
An Swoosh.Email struct can be delivered to an email address by a Swoosh mailer (see mailer.ex). Eg:
1
Remindly.Email.confirm_register_email(user.email, url)
2
|> Remindly.Mailer.deliver()
Copied!
So email.ex creates the Swoosh structs and the functions for actually delivering emails like the previous code example are in user_notifier.ex. Think of email.ex functions like view templates, and user_notifer.ex functions like controller actions.
So the steps to creating a new email will be:
  1. 1.
    Create the function to generate a Swoosh struct in email.ex
  2. 2.
    Ensure it looks good by navigating to "http://localhost:4000/dev/emails" and creating a new action in email_testing_controller.ex that simply renders the html_body value of the struct
  3. 3.
    Create a new user_notifier.ex function for use in our application
To see a more detailed write up on creating an email - see this section in the "Complete web app" guide.
Copy link