Skip to content

Commit

Permalink
reply_to in ezSendgrid
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Jan 29, 2025
1 parent a4a7638 commit fd1752f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/tools/sendgrid/ezSendgrid.ml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ let send ?encoding ~api_key input =
sendgrid_host
(send encoding)

let send_one ~api_key ~dst ~from ~subject content =
let send_one ?reply_to ~api_key ~dst ~from ~subject content =
let person = {
dst = [ {email = fst dst; name = snd dst} ];
cc = None; bcc = None; psubject = None; data = None } in
let reply_to = Option.map (fun (email, name) -> {email; name}) reply_to in
let content =
List.map
(fun (content_type, content_value) ->
Expand All @@ -35,18 +36,21 @@ let send_one ~api_key ~dst ~from ~subject content =
subject = Some subject;
content = Some content;
template_id = None;
reply_to;
more_fields = None;
} in
send ~api_key mail

let send_template ~api_key ~dst ~from template_id data =
let send_template ?reply_to ~api_key ~dst ~from template_id data =
let person = {
dst = List.map (fun (email, name) -> {email; name}) dst;
cc = None; bcc = None; psubject = None;
data = Some (EzEncoding.destruct Json_encoding.any_value data) } in
let reply_to = Option.map (fun (email, name) -> {email; name}) reply_to in
let mail = {
person = [ person ];
from = {email = fst from; name = snd from};
reply_to;
subject = None;
content = None;
template_id = Some template_id;
Expand Down
13 changes: 7 additions & 6 deletions src/tools/sendgrid/ezSendgrid_encoding.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,18 @@ let person = conv

let mail more_encoding =
conv
(fun {person; from; subject; content; template_id; more_fields}
-> (person, from, subject, content, template_id), more_fields)
(fun ((person, from, subject, content, template_id), more_fields)
-> {person; from; subject; content; template_id; more_fields}) @@
(fun {person; from; subject; content; template_id; reply_to; more_fields}
-> (person, from, subject, content, template_id, reply_to), more_fields)
(fun ((person, from, subject, content, template_id, reply_to), more_fields)
-> {person; from; subject; content; template_id; reply_to; more_fields}) @@
merge_objs
(obj5
(obj6
(req "personalizations" (list person))
(req "from" email_address)
(opt "subject" string)
(opt "content" (list content_element))
(opt "template_id" string))
(opt "template_id" string)
(opt "reply_to" email_address))
(opt_encoding more_encoding)

let contact = conv
Expand Down
1 change: 1 addition & 0 deletions src/tools/sendgrid/ezSendgrid_types.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type 'a mail = {
subject : string option;
content: content_element list option;
template_id : string option;
reply_to: email_address option;
more_fields : 'a option;
}

Expand Down

0 comments on commit fd1752f

Please sign in to comment.