Skip to content

Open source, privacy-first web analytics. Lightweight, cookie-free Google Analytics alternative. Self-hosted or cloud.

add MAILER_NAME (#2937)

ruslandogace7401dd837e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index b293d0c130..1451c7ed20 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -9,6 +9,7 @@ All notable changes to this project will be documented in this file.
- 'Last updated X seconds ago' info to 'current visitors' tooltips
- Add support for more Bamboo adapters, i.e. `Bamboo.MailgunAdapter`, `Bamboo.MandrillAdapter`, `Bamboo.SendGridAdapter` plausible/analytics#2649
- Ability to change domain for existing site (requires numeric IDs data migration, instructions will be provided separately) UI + API (`PUT /api/v1/sites`)
+- Add `MAILER_NAME` environment variable support plausible/analytics#2937
- Add `MAILGUN_BASE_URI` support for `Bamboo.MailgunAdapter` plausible/analytics#2935
### Fixed
diff --git a/config/runtime.exs b/config/runtime.exs
index 46ad8e0b43..315a9040a7 100644
--- a/config/runtime.exs
+++ b/config/runtime.exs
@@ -72,6 +72,14 @@ super_admin_user_ids =
env = get_var_from_path_or_env(config_dir, "ENVIRONMENT", "prod")
mailer_adapter = get_var_from_path_or_env(config_dir, "MAILER_ADAPTER", "Bamboo.SMTPAdapter")
mailer_email = get_var_from_path_or_env(config_dir, "MAILER_EMAIL", "[email protected]")
+
+mailer_email =
+ if mailer_name = get_var_from_path_or_env(config_dir, "MAILER_NAME") do
+ {mailer_name, mailer_email}
+ else
+ mailer_email
+ end
+
app_version = get_var_from_path_or_env(config_dir, "APP_VERSION", "0.0.1")
ch_db_url =
diff --git a/test/plausible/config_test.exs b/test/plausible/config_test.exs
index 5071b7cb28..62ffe8702b 100644
--- a/test/plausible/config_test.exs
+++ b/test/plausible/config_test.exs
@@ -2,6 +2,28 @@ defmodule Plausible.ConfigTest do
use ExUnit.Case
describe "mailer" do
+ test "mailer email default" do
+ env = [{"MAILER_EMAIL", nil}]
+ assert get_in(runtime_config(env), [:plausible, :mailer_email]) == "[email protected]"
+ end
+
+ test "mailer email custom" do
+ env = [{"MAILER_EMAIL", "[email protected]"}]
+ assert get_in(runtime_config(env), [:plausible, :mailer_email]) == "[email protected]"
+ end
+
+ test "mailer name" do
+ env = [{"MAILER_EMAIL", nil}, {"MAILER_NAME", "John"}]
+
+ assert get_in(runtime_config(env), [:plausible, :mailer_email]) ==
+ {"John", "[email protected]"}
+
+ env = [{"MAILER_EMAIL", "[email protected]"}, {"MAILER_NAME", "John"}]
+
+ assert get_in(runtime_config(env), [:plausible, :mailer_email]) ==
+ {"John", "[email protected]"}
+ end
+
test "defaults to Bamboo.SMTPAdapter" do
env = {"MAILER_ADAPTER", nil}
diff --git a/test/plausible/mailer_test.exs b/test/plausible/mailer_test.exs
new file mode 100644
index 0000000000..48cd2f76d0
--- /dev/null
+++ b/test/plausible/mailer_test.exs
@@ -0,0 +1,33 @@
+defmodule Plausible.MailerTest do
+ use Plausible.DataCase
+ use Bamboo.Test
+
+ describe "from" do
+ setup do
+ {:ok, user: insert(:user)}
+ end
+
+ # see config tests as well
+ test "when MAILER_NAME and MAILER_EMAIL", %{user: user} do
+ mailer_email = {"John", "[email protected]"}
+ patch_env(:mailer_email, mailer_email)
+
+ email = PlausibleWeb.Email.welcome_email(user)
+ assert :ok = Plausible.Mailer.send(email)
+
+ assert_delivered_email(email)
+ assert email.from == mailer_email
+ end
+
+ test "when MAILER_EMAIL", %{user: user} do
+ mailer_email = "[email protected]"
+ patch_env(:mailer_email, mailer_email)
+
+ email = PlausibleWeb.Email.welcome_email(user)
+ assert :ok = Plausible.Mailer.send(email)
+
+ assert_delivered_email(email)
+ assert email.from == mailer_email
+ end
+ end
+end