From 608cb2ffdaff7db6b3af0630980d84af6e7099ce Mon Sep 17 00:00:00 2001 From: cking285 Date: Wed, 20 Dec 2023 14:02:46 -0800 Subject: [PATCH] feat(hostname): hostname can now be configured for gen_smtp --- lib/mailman/external_smtp_adapter.ex | 37 +++++++++++++++++++--------- lib/mailman/smtp_config.ex | 1 + 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/mailman/external_smtp_adapter.ex b/lib/mailman/external_smtp_adapter.ex index c6b3f22..f9e757e 100644 --- a/lib/mailman/external_smtp_adapter.ex +++ b/lib/mailman/external_smtp_adapter.ex @@ -7,16 +7,6 @@ defmodule Mailman.ExternalSmtpAdapter do Delivers an email based on specified config. """ def deliver(config, email, message) do - relay_config = [ - relay: config.relay, - username: config.username, - password: config.password, - port: config.port, - ssl: config.ssl, - tls: config.tls, - auth: config.auth - ] - from_envelope_address = email.from to_envelope_address = email.to @@ -27,7 +17,7 @@ defmodule Mailman.ExternalSmtpAdapter do to_envelope_address, message }, - relay_config + build_relay_config(config) ) case ret do @@ -36,4 +26,29 @@ defmodule Mailman.ExternalSmtpAdapter do _ -> {:ok, message} end end + + defp build_relay_config(%{hostname: nil} = config) do + [ + relay: config.relay, + username: config.username, + password: config.password, + port: config.port, + ssl: config.ssl, + tls: config.tls, + auth: config.auth + ] + end + + defp build_relay_config(config) do + [ + relay: config.relay, + username: config.username, + password: config.password, + port: config.port, + ssl: config.ssl, + tls: config.tls, + auth: config.auth, + hostname: config.hostname + ] + end end diff --git a/lib/mailman/smtp_config.ex b/lib/mailman/smtp_config.ex index 0bef818..a1c1fde 100644 --- a/lib/mailman/smtp_config.ex +++ b/lib/mailman/smtp_config.ex @@ -10,6 +10,7 @@ defmodule Mailman.SmtpConfig do port: 1111, ssl: false, tls: :never, + hostname: nil, auth: :always end