Skip to content
Permalink
Browse files
Code for step 3
  • Loading branch information
akoutmos committed Jan 20, 2021
1 parent 0801ac3 commit 315c95c
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
@@ -9,6 +9,8 @@ config :mjml_demo, MjmlDemo.Repo,
show_sensitive_data_on_connection_error: true,
pool_size: 10

config :mjml_demo, MjmlDemo.Emails, adapter: Swoosh.Adapters.Local

# For development, we disable any cache and enable
# debugging and code reloading.
#
@@ -0,0 +1,44 @@
defmodule MjmlDemo.Emails do
use Swoosh.Mailer, otp_app: :mjml_demo

import Swoosh.Email

alias __MODULE__.ConfirmationInstructions

def confirmation_instructions(user, confirmation_url) do
# You'll want to update the User schema and the DB migration to support
# storing first+last names, plan tiers, and whatever else you want to
# associate to the user registration.
rendered_email =
ConfirmationInstructions.render(
first_name: "Agent",
last_name: "Smith",
confirmation_url: confirmation_url,
tier: "Gold"
)

new()
|> to(user.email)
|> from({"Onboarding Team", "welcome@saas-central.com"})
|> subject("Welcome to SaaS-Central!")
|> html_body(rendered_email)
|> text_body("""
Hello Agent Smith and thank you for signing up for the Gold plan!!!
You can confirm your account by visiting the following URL: #{confirmation_url}
""")
|> deliver()
end

def generate_template(file_path) do
{:ok, template} =
file_path
|> File.read!()
|> Mjml.to_html()

~r/{{\s*([^}^\s]+)\s*}}/
|> Regex.replace(template, fn _, variable_name ->
"<%= @#{variable_name} %>"
end)
end
end
@@ -43,6 +43,14 @@ defmodule MjmlDemoWeb.Router do
end
end

if Mix.env() == :dev do
scope "/dev" do
pipe_through [:browser]

forward "/mailbox", Plug.Swoosh.MailboxPreview, base_path: "/dev/mailbox"
end
end

## Authentication routes

scope "/", MjmlDemoWeb do

0 comments on commit 315c95c

Please sign in to comment.