LogoLogo
v1.2.0
v1.2.0
  • 🌸What is Petal Pro?
  • 💡V1.2.0 Overview
  • ⏫Upgrade guide
  • Guides
    • 🚀Creating a web app from start to finish
  • Fundamentals
    • 💿Installation
    • 📂Folder structure
    • 🗃️Included Pages
    • 😀Users & Authentication
    • 🏢Organizations & Multitenancy
    • 🧊Components
    • 🎨Branding
    • 🌱Seeding
    • 📄Layouts & Menus
    • 🛠️Background Tasks and Jobs
    • 🔧Util, DB & Helpers
    • 📧Emails
    • 🪝Javascript Hooks
    • 📚Extra Hex Libraries
    • 🏗️Generators & Page Builder
    • 🗣️Translations
    • 🖐️Contributing
    • 🛫Deployment
Powered by GitBook
On this page

Was this helpful?

  1. Fundamentals

Emails

PreviousUtil, DB & HelpersNextJavascript Hooks

Last updated 3 years ago

Was this helpful?

Open up email.ex and you will see a list of functions that generate Swoosh email structs. Eg:

def confirm_register_email(email, url) do
  base_email()
  |> to(email)
  |> subject("Confirm instructions")
  |> render_body("confirm_register_email.html", %{url: url})
  |> premail()
end

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:

  Remindly.Email.confirm_register_email(user.email, url)
  |> Remindly.Mailer.deliver()

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. Create the function to generate a Swoosh struct in email.ex

  2. Create a new user_notifier.ex function for use in our application

Ensure it looks good by navigating to "" and creating a new action in email_testing_controller.ex that simply renders the html_body value of the struct

To see a more detailed write up on creating an email - see in the "Complete web app" guide.

📧
http://localhost:4000/dev/emails
this section