· 6 years ago · Mar 10, 2020, 07:36 AM
1(use ./config)
2(import process)
3(import json)
4
5(defn send-email
6 [{:send-domain domain
7 :private-key key
8 :from from
9 :to to
10 :subject subject
11 :text text}]
12
13 (def out @"")
14 (def out-err @"")
15
16 (if (zero? (process/run [
17 "curl"
18 "-s"
19 "-X" "POST"
20 "--user" (string "api:" key)
21 (string/format "https://api.mailgun.net/v3/%s/messages" domain)
22 "-F" (string "from=" from)
23 "-F" (string "to=" to)
24 "-F" (string "subject=" subject)
25 "-F" "text=<-"
26 ] :redirects [[stdin text] [stdout out] [stderr out-err]]))
27 (do
28 (def [ok response] (protect (json/decode out)))
29 (if ok
30 (in response "id")
31 (error response)))
32 (error (string "mailgun curl error:\nstdout:\n" out "\nstderr:\n" out-err))))