add MAILER_NAME (#2937)

* add MAILER_NAME

* add mailer test

---------

Co-authored-by: Uku Taht <Uku.taht@gmail.com>
This commit is contained in:
ruslandoga 2023-05-25 15:34:39 +08:00 committed by GitHub
parent e4b1aa64d1
commit ce7401dd83
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 0 deletions

View File

@ -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

View File

@ -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", "hello@plausible.local")
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 =

View File

@ -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]) == "hello@plausible.local"
end
test "mailer email custom" do
env = [{"MAILER_EMAIL", "custom@mailer.email"}]
assert get_in(runtime_config(env), [:plausible, :mailer_email]) == "custom@mailer.email"
end
test "mailer name" do
env = [{"MAILER_EMAIL", nil}, {"MAILER_NAME", "John"}]
assert get_in(runtime_config(env), [:plausible, :mailer_email]) ==
{"John", "hello@plausible.local"}
env = [{"MAILER_EMAIL", "custom@mailer.email"}, {"MAILER_NAME", "John"}]
assert get_in(runtime_config(env), [:plausible, :mailer_email]) ==
{"John", "custom@mailer.email"}
end
test "defaults to Bamboo.SMTPAdapter" do
env = {"MAILER_ADAPTER", nil}

View File

@ -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", "custom@mailer.email"}
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 = "custom@mailer.email"
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