2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.Email do
|
|
|
|
use Bamboo.Phoenix, view: PlausibleWeb.EmailView
|
|
|
|
import Bamboo.PostmarkHelper
|
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
def mailer_email_from do
|
|
|
|
Application.get_env(:plausible, :mailer_email)
|
|
|
|
end
|
|
|
|
|
2020-03-23 12:34:25 +03:00
|
|
|
def activation_email(user, link) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-03-23 12:34:25 +03:00
|
|
|
|> to(user.email)
|
|
|
|
|> tag("activation-email")
|
|
|
|
|> subject("Activate your Plausible free trial")
|
|
|
|
|> render("activation_email.html", name: user.name, link: link)
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
def welcome_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("welcome-email")
|
2020-03-23 12:34:25 +03:00
|
|
|
|> subject("Welcome to Plausible")
|
2019-09-02 14:29:19 +03:00
|
|
|
|> render("welcome_email.html", user: user)
|
|
|
|
end
|
|
|
|
|
2020-03-23 12:34:25 +03:00
|
|
|
def create_site_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-03-23 12:34:25 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("create-site-email")
|
|
|
|
|> subject("Your Plausible setup: Add your website details")
|
|
|
|
|> render("create_site_email.html", user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
def site_setup_help(user, site) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("help-email")
|
2020-03-23 12:34:25 +03:00
|
|
|
|> subject("Your Plausible setup: Waiting for the first page views")
|
|
|
|
|> render("site_setup_help_email.html", user: user, site: site)
|
|
|
|
end
|
|
|
|
|
|
|
|
def site_setup_success(user, site) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-03-23 12:34:25 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("setup-success-email")
|
|
|
|
|> subject("Plausible is now tracking your website stats")
|
|
|
|
|> render("site_setup_success_email.html", user: user, site: site)
|
|
|
|
end
|
|
|
|
|
|
|
|
def check_stats_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2020-03-23 12:34:25 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("check-stats-email")
|
|
|
|
|> subject("Check your Plausible website stats")
|
|
|
|
|> render("check_stats_email.html", user: user)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def password_reset_email(email, reset_link) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(email)
|
|
|
|
|> tag("password-reset-email")
|
|
|
|
|> subject("Plausible password reset")
|
|
|
|
|> render("password_reset_email.html", reset_link: reset_link)
|
|
|
|
end
|
|
|
|
|
2020-03-23 12:34:25 +03:00
|
|
|
def trial_one_week_reminder(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
2020-03-23 12:34:25 +03:00
|
|
|
|> tag("trial-one-week-reminder")
|
2020-03-24 16:29:44 +03:00
|
|
|
|> subject("Your Plausible trial expires next week")
|
2020-03-23 12:34:25 +03:00
|
|
|
|> render("trial_one_week_reminder.html", user: user)
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def trial_upgrade_email(user, day, pageviews) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("trial-upgrade-email")
|
|
|
|
|> subject("Your Plausible trial ends #{day}")
|
|
|
|
|> render("trial_upgrade_email.html", user: user, day: day, pageviews: pageviews)
|
|
|
|
end
|
|
|
|
|
|
|
|
def trial_over_email(user) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-02 14:29:19 +03:00
|
|
|
|> to(user)
|
|
|
|
|> tag("trial-over-email")
|
|
|
|
|> subject("Your Plausible trial has ended")
|
|
|
|
|> render("trial_over_email.html", user: user)
|
|
|
|
end
|
|
|
|
|
2019-09-05 19:11:07 +03:00
|
|
|
def weekly_report(email, site, assigns) do
|
2020-05-11 14:27:20 +03:00
|
|
|
base_email()
|
2019-09-05 19:11:07 +03:00
|
|
|
|> to(email)
|
|
|
|
|> tag("weekly-report")
|
2020-01-22 12:16:53 +03:00
|
|
|
|> subject("#{assigns[:name]} report for #{site.domain}")
|
2019-09-05 19:11:07 +03:00
|
|
|
|> render("weekly_report.html", Keyword.put(assigns, :site, site))
|
|
|
|
end
|
2020-05-11 14:27:20 +03:00
|
|
|
|
2020-12-09 12:00:14 +03:00
|
|
|
def spike_notification(email, site, current_visitors) do
|
|
|
|
base_email()
|
|
|
|
|> to(email)
|
|
|
|
|> tag("spike-notification")
|
|
|
|
|> subject("Traffic spike on #{site.domain}")
|
|
|
|
|> render("spike_notification.html", %{current_visitors: current_visitors})
|
|
|
|
end
|
|
|
|
|
2020-09-18 15:35:21 +03:00
|
|
|
def cancellation_email(user) do
|
|
|
|
base_email()
|
|
|
|
|> to(user.email)
|
|
|
|
|> tag("cancelled-email")
|
|
|
|
|> subject("Your Plausible Analytics subscription has been canceled")
|
|
|
|
|> render("cancellation_email.html", name: user.name)
|
|
|
|
end
|
|
|
|
|
2020-05-11 14:27:20 +03:00
|
|
|
defp base_email() do
|
2020-09-18 15:35:21 +03:00
|
|
|
mailer_from = Application.get_env(:plausible, :mailer_email)
|
|
|
|
|
2020-05-11 14:27:20 +03:00
|
|
|
new_email()
|
|
|
|
|> put_param("TrackOpens", false)
|
2020-09-18 15:35:21 +03:00
|
|
|
|> from(mailer_from)
|
2020-05-11 14:27:20 +03:00
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|