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