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