Skip to content

Commit d9ff65f

Browse files
authored
Support TLS Version as an Option within SMTP (#2268)
In order for NervesHub to work against AWS SES, we need to be able to set TLS Version to 1.2. The default that happens with Swoosh isn't supporting what SES expects. This change permits the option to set TLS_VERSION or leave it to default within the Swoosh
1 parent 2738c50 commit d9ff65f

File tree

1 file changed

+17
-9
lines changed

1 file changed

+17
-9
lines changed

config/runtime.exs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,13 @@ if config_env() == :prod do
370370
config :swoosh, local: false
371371

372372
if System.get_env("SMTP_SERVER") do
373+
tls_versions =
374+
System.get_env("SMTP_TLS_VERSIONS", "")
375+
|> String.split(",")
376+
|> Enum.map(&String.to_atom/1)
377+
378+
tls_opts = if Enum.any?(tls_versions), do: [versions: tls_versions], else: []
379+
373380
config :nerves_hub, NervesHub.SwooshMailer,
374381
adapter: Swoosh.Adapters.SMTP,
375382
relay: System.fetch_env!("SMTP_SERVER"),
@@ -379,15 +386,16 @@ if config_env() == :prod do
379386
auth: :always,
380387
ssl: System.get_env("SMTP_SSL", "false") == "true",
381388
tls: :always,
382-
tls_options: [
383-
verify: :verify_peer,
384-
cacerts: :public_key.cacerts_get(),
385-
depth: 99,
386-
server_name_indication: String.to_charlist(System.get_env("SMTP_SERVER")),
387-
customize_hostname_check: [
388-
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
389-
]
390-
],
389+
tls_options:
390+
[
391+
verify: :verify_peer,
392+
cacerts: :public_key.cacerts_get(),
393+
depth: 99,
394+
server_name_indication: String.to_charlist(System.get_env("SMTP_SERVER")),
395+
customize_hostname_check: [
396+
match_fun: :public_key.pkix_verify_hostname_match_fun(:https)
397+
]
398+
] ++ tls_opts,
391399
retries: 1
392400
end
393401
end

0 commit comments

Comments
 (0)