-
Notifications
You must be signed in to change notification settings - Fork 12
/
mailgun.red
55 lines (49 loc) · 1.67 KB
/
mailgun.red
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
Red[
Title: "Mailgun API"
Author: "Boleslav Březovský"
Usage: {
Make your own `mailgun` object like this:
```
my-mailgun: make mailgun! [
api: <your API key>
domain: <your domain>
from: <your email address>
]
```
}
API: https://documentation.mailgun.com/en/latest
]
;sony@deli:~/Code/temp$ curl -s --user 'api:key-3c3fad7221f6f700b13724fab19cfd0c' \
;> https://api.mailgun.net/v3/sandbox915666ebdc3a47ddaff441ebff290da1.mailgun.org/messages \
;> -F from='Mailgun Sandbox <[email protected]>' \
;> -F to='Ivan Vrah <[email protected]>' \
;> -F subject='Hello Ivan Vrah' \
;> -F text='Congratulations Ivan Vrah, you just sent an email with Mailgun! You are truly awesome!'
do %http-tools.red
mailgun!: context [
api: none ; put your API key here
base-url: https://api.mailgun.net/v3/
domain: none ; put your domain here
from: none ; put your email address here
send: func [
recepients
subject ; TODO: get subject from body as first line?
body
/local ret link method
][
link: rejoin [base-url self/domain /messages]
method: 'POST
data: ""
headers: make map! compose [
from: (self/from)
to: (recepients) ; TODO: conversion to comma separated format
; TODO: CC, BCC
subject: (subject)
text: (body)
; TODO: Attachment and other headers
]
ret: send-request/auth/data/with link method 'basic reduce ["api" self/api] data headers
load-json ret
; TODO: Error handling
]
]