Skip to content
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

Add multi mail #7

Open
wants to merge 1 commit into
base: main
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
9 changes: 1 addition & 8 deletions .env
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
SIHL_SECRET=secret
SIHL_SECRET=secretsecretsecret
DATABASE_URL=postgres://admin:[email protected]:5432/dev
DATABASE_POOL_SIZE=10
[email protected]
SMTP_PORT=587
SMTP_USERNAME=user
SMTP_HOST=smtp.example.com
SMTP_START_TLS=true
SMTP_PASSWORD=yourpassword
CA_DIR=/etc/ssl/certs
4 changes: 2 additions & 2 deletions app/context/pizza/pizza.ml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ include Model

exception Exception of string

let clean =
let clean () =
if Sihl.Configuration.is_production ()
then
raise
@@ Exception
"Can not clean repository in production, this is most likely not what \
you want"
else Repo.clean
else Repo.clean ()
;;

let find_ingredient name = Repo.find_ingredient name
Expand Down
7 changes: 7 additions & 0 deletions config/mail.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[email protected]
SMTP_USERNAME=user
SMTP_PASSWORD=yourpassword
SMTP_HOST=smtp.example.com
SMTP_PORT=587
SMTP_START_TLS=true
CA_DIR=/etc/ssl/certs
7 changes: 4 additions & 3 deletions dune-project
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,10 @@ A restaurant serving Pizza and sometimes Lasagna
(depends
(ocaml (>= 4.08.0))
dune
(sihl (= 0.4.0))
(sihl-user (= 0.4.0))
(sihl-queue (= 0.4.0))
(sihl (= 0.4.1))
(sihl-user (= 0.4.1))
(sihl-queue (= 0.4.1))
(sihl-email (= 0.4.1))
(tyxml-ppx (>= 4.4.0))
(caqti-driver-postgresql (>= 1.2.1))
(alcotest-lwt :with-test)
Expand Down
7 changes: 4 additions & 3 deletions pizza.opam
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ bug-reports: "https://github.com/oxidizing/pizza/issues"
depends: [
"ocaml" {>= "4.08.0"}
"dune"
"sihl" {= "0.4.0"}
"sihl-user" {= "0.4.0"}
"sihl-queue" {= "0.4.0"}
"sihl" {= "0.4.1"}
"sihl-user" {= "0.4.1"}
"sihl-queue" {= "0.4.1"}
"sihl-email" {= "0.4.1"}
"tyxml-ppx" {>= "4.4.0"}
"caqti-driver-postgresql" {>= "1.2.1"}
"alcotest-lwt" {with-test}
Expand Down
7 changes: 4 additions & 3 deletions pizza.opam.locked
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,10 @@ depends: [
"seq" {= "base"}
"sexplib" {= "v0.14.0"}
"sexplib0" {= "v0.14.0"}
"sihl" {= "0.4.0"}
"sihl-queue" {= "0.4.0"}
"sihl-user" {= "0.4.0"}
"sihl" {= "0.4.1"}
"sihl-email" {= "0.4.1"}
"sihl-queue" {= "0.4.1"}
"sihl-user" {= "0.4.1"}
"ssl" {= "0.5.10"}
"stdlib-shims" {= "0.3.0"}
"stringext" {= "1.6.0"}
Expand Down
2 changes: 2 additions & 0 deletions run/run.ml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ let services =
~jobs:
[ Sihl_queue.hide Job.cook_pizza; Sihl_queue.hide Job.order_ingredient ]
()
; Service.MarketingMail.register ()
; Service.InfoMail.register ()
]
;;

Expand Down
2 changes: 1 addition & 1 deletion service/dune
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
(library
(name service)
(libraries sihl sihl-user sihl-queue))
(libraries sihl sihl-user sihl-queue sihl-email))
54 changes: 54 additions & 0 deletions service/service.ml
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
module Migration = Sihl.Database.Migration.PostgreSql
module User = Sihl_user.PostgreSql
module Queue = Sihl_queue.PostgreSql

module MarketingSmtpConfig = struct
let config () =
Lwt.return
Sihl_email.
{ sender = "[email protected]"
; username = "vinnie"
; password = "pinapple0nPizz4"
; hostname = "smtp.example.com"
; port = Some 587
; start_tls = true
; ca_path = Some "/etc/ssl/certs"
; ca_cert = None
; console = Some true
}
;;
end

module InfoSmtpConfig = struct
let config () =
let open Lwt.Syntax in
Lwt_io.with_file ~mode:Lwt_io.Input "config/mail.cfg" (fun file ->
let* content = Lwt_stream.to_list @@ Lwt_io.read_lines file in
let config =
content
|> Stdlib.List.map (Stdlib.String.split_on_char '=')
|> Stdlib.List.map (function
| [] -> "", ""
| [ key ] -> key, ""
| [ key; value ] -> key, value
| key :: values -> key, Stdlib.String.concat "" values)
in
Lwt.return
Sihl_email.
{ sender = Stdlib.List.assoc "SMTP_SENDER" config
; username = Stdlib.List.assoc "SMTP_USERNAME" config
; password = Stdlib.List.assoc "SMTP_PASSWORD" config
; hostname = Stdlib.List.assoc "SMTP_HOST" config
; port =
Option.map int_of_string
@@ Stdlib.List.assoc_opt "SMTP_PORT" config
; start_tls =
bool_of_string @@ Stdlib.List.assoc "SMTP_START_TLS" config
; ca_path = Stdlib.List.assoc_opt "CA_DIR" config
; ca_cert = Stdlib.List.assoc_opt "CA_PATH" config
; console =
Option.map bool_of_string
@@ Stdlib.List.assoc_opt "SMTP_CONSOLE" config
})
;;
end

module MarketingMail = Sihl_email.MakeSmtp (MarketingSmtpConfig)
module InfoMail = Sihl_email.MakeSmtp (InfoSmtpConfig)