@@ -76,16 +76,6 @@ email_confirmation =
7676pool_size = get_int_from_path_or_env ( config_dir , "POOL_SIZE" , 10 )
7777queue_target = get_int_from_path_or_env ( config_dir , "QUEUE_TARGET" , 5_000 )
7878
79- mail_transport = get_var_from_path_or_env ( config_dir , "MAIL_TRANSPORT" , "local" )
80-
81- smtp_relay = get_var_from_path_or_env ( config_dir , "SMTP_RELAY" , nil )
82- smtp_username = get_var_from_path_or_env ( config_dir , "SMTP_USERNAME" , nil )
83- smtp_password = get_var_from_path_or_env ( config_dir , "SMTP_PASSWORD" , nil )
84- smtp_ssl = get_var_from_path_or_env ( config_dir , "SMTP_SSL" , "true" ) |> String . to_existing_atom ( )
85- smtp_tls = get_var_from_path_or_env ( config_dir , "SMTP_TLS" , "always" )
86- smtp_auth = get_var_from_path_or_env ( config_dir , "SMTP_AUTH" , "always" )
87- smtp_port = get_int_from_path_or_env ( config_dir , "SMTP_PORT" , 25 )
88-
8979storage = get_var_from_path_or_env ( config_dir , "PRESENTATION_STORAGE" , "local" )
9080if storage not in [ "local" , "s3" ] , do: raise ( "Invalid PRESENTATION_STORAGE value #{ storage } " )
9181
@@ -222,26 +212,45 @@ config :claper, ClaperWeb.MailboxGuard,
222212 get_var_from_path_or_env ( config_dir , "ENABLE_MAILBOX_ROUTE" , "false" )
223213 |> String . to_existing_atom ( )
224214
225- case mail_transport do
215+ case get_var_from_path_or_env ( config_dir , "MAIL_TRANSPORT" , "local" ) do
226216 "smtp" ->
217+ relay = get_var_from_path_or_env ( config_dir , "SMTP_RELAY" , nil )
218+ ssl = get_var_from_path_or_env ( config_dir , "SMTP_SSL" , "true" )
219+ depth = get_int_from_path_or_env ( config_dir , "SMTP_SSL_DEPTH" , 2 )
220+
221+ server =
222+ get_var_from_path_or_env ( config_dir , "SMTP_SSL_SERVER" , relay )
223+ |> to_charlist ( )
224+
227225 config :claper , Claper.Mailer ,
228- adapter: Swoosh.Adapters.Mua ,
229- relay: smtp_relay ,
230- port: smtp_port
231-
232- cond do
233- smtp_username && smtp_password ->
234- config :claper , Claper.Mailer , auth: [ username: smtp_username , password: smtp_password ]
235-
236- smtp_username || smtp_password ->
237- raise ArgumentError , """
238- Both SMTP_USERNAME and SMTP_PASSWORD must be set for SMTP authentication.
239- Please provide values for both environment variables.
240- """
241-
242- true ->
243- nil
244- end
226+ adapter: Swoosh.Adapters.SMTP ,
227+ relay: relay ,
228+ port: get_int_from_path_or_env ( config_dir , "SMTP_PORT" , 465 ) ,
229+ auth: get_var_from_path_or_env ( config_dir , "SMTP_AUTH" , "always" ) ,
230+ username: get_var_from_path_or_env ( config_dir , "SMTP_USERNAME" , "" ) ,
231+ password: get_var_from_path_or_env ( config_dir , "SMTP_PASSWORD" , "" ) ,
232+ retries: get_int_from_path_or_env ( config_dir , "SMTP_RETRIES" , 1 ) ,
233+ no_mx_lookups: get_var_from_path_or_env ( config_dir , "SMTP_NO_MX_LOOKUPS" , "false" ) ,
234+ ssl: ssl ,
235+ sockopts:
236+ if ( ssl == "true" ,
237+ do: [
238+ versions: [ :"tlsv1.3" , :"tlsv1.2" ] ,
239+ verify: :verify_peer ,
240+ cacerts: :public_key . cacerts_get ( ) ,
241+ depth: depth ,
242+ server_name_indication: server
243+ ] ,
244+ else: [ ]
245+ ) ,
246+ tls: get_var_from_path_or_env ( config_dir , "SMTP_TLS" , "if_available" ) ,
247+ tls_options: [
248+ versions: [ :"tlsv1.3" , :"tlsv1.2" ] ,
249+ verify: :verify_peer ,
250+ cacerts: :public_key . cacerts_get ( ) ,
251+ depth: depth ,
252+ server_name_indication: server
253+ ]
245254
246255 config :swoosh , :api_client , false
247256
@@ -250,7 +259,7 @@ case mail_transport do
250259 adapter: Swoosh.Adapters.Postmark ,
251260 api_key: get_var_from_path_or_env ( config_dir , "POSTMARK_API_KEY" , nil )
252261
253- config :swoosh , :api_client , Swoosh.ApiClient.Hackney
262+ config :swoosh , :api_client , Swoosh.ApiClient.Finch
254263
255264 _ ->
256265 config :claper , Claper.Mailer , adapter: Swoosh.Adapters.Local
@@ -263,5 +272,3 @@ config :ex_aws,
263272 region: s3_region ,
264273 normalize_path: false ,
265274 s3: [ scheme: s3_scheme , host: s3_host , port: s3_port ]
266-
267- config :swoosh , :api_client , Swoosh.ApiClient.Finch
0 commit comments