Skip to content

feat(hostname): hostname can now be configured for gen_smtp #99

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 26 additions & 11 deletions lib/mailman/external_smtp_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -27,7 +17,7 @@ defmodule Mailman.ExternalSmtpAdapter do
to_envelope_address,
message
},
relay_config
build_relay_config(config)
)

case ret do
Expand All @@ -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
1 change: 1 addition & 0 deletions lib/mailman/smtp_config.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ defmodule Mailman.SmtpConfig do
port: 1111,
ssl: false,
tls: :never,
hostname: nil,
auth: :always

end
Expand Down