From b45e2af4dced7408f565e757fc2aadfc609017bc Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Thu, 7 May 2026 16:34:55 +0100 Subject: [PATCH] configure mail --- app/config/runtime.exs | 11 +++++++++++ app/lib/firehose/accounts/user_notifier.ex | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/config/runtime.exs b/app/config/runtime.exs index 162e9cb..e87ffd8 100644 --- a/app/config/runtime.exs +++ b/app/config/runtime.exs @@ -118,4 +118,15 @@ if config_env() == :prod do # config :swoosh, :api_client, Swoosh.ApiClient.Req # # See https://hexdocs.pm/swoosh/Swoosh.html#module-installation for details. + + config :firehose, Firehose.Mailer, + adapter: Swoosh.Adapters.SMTP, + server: System.get_env("SMTP_HOST"), + port: String.to_integer(System.get_env("SMTP_PORT") || "587"), + username: System.get_env("SMTP_USERNAME"), + password: System.get_env("SMTP_PASSWORD"), + ssl: System.get_env("SMTP_SSL") in ~w(true 1), + tls: System.get_env("SMTP_TLS") in ~w(true 1) || System.get_env("SMTP_SSL") not in ~w(true 1), + retries: 2, + no_dns_lookup: true end diff --git a/app/lib/firehose/accounts/user_notifier.ex b/app/lib/firehose/accounts/user_notifier.ex index 9cb0757..00a21c7 100644 --- a/app/lib/firehose/accounts/user_notifier.ex +++ b/app/lib/firehose/accounts/user_notifier.ex @@ -11,12 +11,18 @@ defmodule Firehose.Accounts.UserNotifier do alias Firehose.Accounts.User alias Firehose.Mailer + defp sender do + name = System.get_env("SENDER_NAME") || "Firehose" + email = System.get_env("SMTP_FROM_EMAIL") || "contact@example.com" + {name, email} + end + # Delivers the email using the application mailer. defp deliver(recipient, subject, body) do email = new() |> to(recipient) - |> from({"Firehose", "contact@example.com"}) + |> from(sender()) |> subject(subject) |> text_body(body)