File tree 3 files changed +23
-12
lines changed
3 files changed +23
-12
lines changed Original file line number Diff line number Diff line change 1
1
import Config
2
2
require Logger
3
3
:ok == Application . ensure_started ( :logger )
4
- :ok == Application . ensure_started ( :tls_certificate_check )
5
4
6
5
exit_from_exception = fn exception , message ->
7
6
Logger . error ( exception . message )
@@ -85,18 +84,10 @@ if config_env() == :prod do
85
84
relay: host ,
86
85
username: user ,
87
86
password: password ,
88
- from_email: from_email
87
+ from_email: from_email ,
88
+ ssl: ssl?
89
89
]
90
90
|> put_if_not_empty . ( :port , port )
91
- |> then ( fn config ->
92
- if ssl? do
93
- config
94
- |> Keyword . put ( :ssl , true )
95
- |> Keyword . put ( :sockopts , :tls_certificate_check . options ( host ) )
96
- else
97
- config
98
- end
99
- end )
100
91
end
101
92
102
93
config ( :keila , Keila.Mailer , config )
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ defmodule Keila.Auth.Emails do
7
7
def send! ( email , params ) do
8
8
email
9
9
|> build ( params )
10
- |> Keila.Mailer . deliver !( )
10
+ |> Keila.Mailer . deliver_system_email !( )
11
11
end
12
12
13
13
@ spec build ( :activate , % { url: String . t ( ) , user: Keila.Auth.User . t ( ) } ) :: term ( ) | no_return ( )
Original file line number Diff line number Diff line change @@ -3,6 +3,26 @@ defmodule Keila.Mailer do
3
3
alias Keila.Mailings.Sender
4
4
alias Keila.Mailings.SharedSender
5
5
6
+ @ doc """
7
+ Delivers an email using the configured system mailer.
8
+ """
9
+ @ spec deliver_system_email! ( Swoosh.Email . t ( ) ) :: term ( )
10
+ def deliver_system_email! ( email ) do
11
+ config =
12
+ Application . get_env ( :keila , __MODULE__ )
13
+ |> maybe_put_tls_opts ( )
14
+
15
+ deliver! ( email , config )
16
+ end
17
+
18
+ defp maybe_put_tls_opts ( config ) do
19
+ if Keyword . get ( config , :ssl ) do
20
+ Keyword . put ( config , :sockopts , :tls_certificate_check . options ( config [ :relay ] ) )
21
+ else
22
+ config
23
+ end
24
+ end
25
+
6
26
@ doc """
7
27
Delivers an email using a given sender.
8
28
"""
You can’t perform that action at this time.
0 commit comments