# Emails

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

```elixir
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:

![](/files/uISqU5rXCD0QWRSQNe6R)

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.&#x20;

So the steps to creating a new email will be:

1. Create the function to generate a Swoosh struct in `email.ex`
2. Ensure it looks good by navigating to "[http://localhost:4000/dev/emails](http://localhost:4000/dev/emails/preview/template)" and creating a new action in `email_testing_controller.ex` that simply renders the html\_body value of the struct
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](/petal-pro-documentation/product-docs/guides/creating-a-web-app-from-start-to-finish.md#reminder-emails) in the "Complete web app" guide.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.petal.build/petal-pro-documentation/product-docs/fundamentals/emails.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
