Skip to content

Commit

Permalink
DRY-up SMTP LF workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
ku1ik committed Jan 18, 2024
1 parent f7ff294 commit 9e5e9f8
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions lib/asciinema/emails/email.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,23 @@ defmodule Asciinema.Emails.Email do
def signup_email(email_address, signup_url) do
hostname = instance_hostname()

email =
base_email()
|> to(email_address)
|> subject("Welcome to #{hostname}")
|> render("signup.text", signup_url: signup_url, hostname: hostname)
|> render("signup.html", signup_url: signup_url, hostname: hostname)

%{email | text_body: String.replace(email.text_body, "\n", "\r\n")}
base_email()
|> to(email_address)
|> subject("Welcome to #{hostname}")
|> render("signup.text", signup_url: signup_url, hostname: hostname)
|> render("signup.html", signup_url: signup_url, hostname: hostname)
|> fix_text_body()
end

def login_email(email_address, login_url) do
hostname = instance_hostname()

email =
base_email()
|> to(email_address)
|> subject("Login to #{hostname}")
|> render("login.text", login_url: login_url, hostname: hostname)
|> render("login.html", login_url: login_url, hostname: hostname)

%{email | text_body: String.replace(email.text_body, "\n", "\r\n")}
base_email()
|> to(email_address)
|> subject("Login to #{hostname}")
|> render("login.text", login_url: login_url, hostname: hostname)
|> render("login.html", login_url: login_url, hostname: hostname)
|> fix_text_body()
end

def test_email(email_address) do
Expand Down Expand Up @@ -56,4 +52,8 @@ defmodule Asciinema.Emails.Email do
defp instance_hostname do
System.get_env("URL_HOST") || "localhost"
end

defp fix_text_body(email) do
%{email | text_body: String.replace(email.text_body, "\n", "\r\n")}
end
end

0 comments on commit 9e5e9f8

Please sign in to comment.