|
1 | 1 | module Migration = Sihl.Database.Migration.PostgreSql |
2 | 2 | module User = Sihl_user.PostgreSql |
3 | 3 | module Queue = Sihl_queue.PostgreSql |
| 4 | + |
| 5 | +module MarketingSmtpConfig = struct |
| 6 | + let config () = |
| 7 | + Lwt.return |
| 8 | + Sihl_email. |
| 9 | + |
| 10 | + ; username = "vinnie" |
| 11 | + ; password = "pinapple0nPizz4" |
| 12 | + ; hostname = "smtp.example.com" |
| 13 | + ; port = Some 587 |
| 14 | + ; start_tls = true |
| 15 | + ; ca_path = Some "/etc/ssl/certs" |
| 16 | + ; ca_cert = None |
| 17 | + ; console = Some true |
| 18 | + } |
| 19 | + ;; |
| 20 | +end |
| 21 | + |
| 22 | +module InfoSmtpConfig = struct |
| 23 | + let config () = |
| 24 | + let open Lwt.Syntax in |
| 25 | + Lwt_io.with_file ~mode:Lwt_io.Input "config/mail.cfg" (fun file -> |
| 26 | + let* content = Lwt_stream.to_list @@ Lwt_io.read_lines file in |
| 27 | + let config = |
| 28 | + content |
| 29 | + |> Stdlib.List.map (Stdlib.String.split_on_char '=') |
| 30 | + |> Stdlib.List.map (function |
| 31 | + | [] -> "", "" |
| 32 | + | [ key ] -> key, "" |
| 33 | + | [ key; value ] -> key, value |
| 34 | + | key :: values -> key, Stdlib.String.concat "" values) |
| 35 | + in |
| 36 | + Lwt.return |
| 37 | + Sihl_email. |
| 38 | + { sender = Stdlib.List.assoc "SMTP_SENDER" config |
| 39 | + ; username = Stdlib.List.assoc "SMTP_USERNAME" config |
| 40 | + ; password = Stdlib.List.assoc "SMTP_PASSWORD" config |
| 41 | + ; hostname = Stdlib.List.assoc "SMTP_HOST" config |
| 42 | + ; port = |
| 43 | + Option.map int_of_string |
| 44 | + @@ Stdlib.List.assoc_opt "SMTP_PORT" config |
| 45 | + ; start_tls = |
| 46 | + bool_of_string @@ Stdlib.List.assoc "SMTP_START_TLS" config |
| 47 | + ; ca_path = Stdlib.List.assoc_opt "CA_DIR" config |
| 48 | + ; ca_cert = Stdlib.List.assoc_opt "CA_PATH" config |
| 49 | + ; console = |
| 50 | + Option.map bool_of_string |
| 51 | + @@ Stdlib.List.assoc_opt "SMTP_CONSOLE" config |
| 52 | + }) |
| 53 | + ;; |
| 54 | +end |
| 55 | + |
| 56 | +module MarketingMail = Sihl_email.MakeSmtp (MarketingSmtpConfig) |
| 57 | +module InfoMail = Sihl_email.MakeSmtp (InfoSmtpConfig) |
0 commit comments