Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 143 lines (104 sloc) 4.528 kb
f997d91 @dpacaud Adding Readme for GitHub
authored
1 Mandrill Grails Plugin
2 =============
3
4 This is a Grails plugin for the mandrill (http://www.mandrill.com) REST API
5
6
7 Supported Methods
8 -------
9 It curently handles :
10
11 * [Ping](https://mandrillapp.com/api/docs/users.html#method=ping)
12 * [Info](https://mandrillapp.com/api/docs/users.html#method=info)
13 * [Send](https://mandrillapp.com/api/docs/messages.html#method=send)
b0a051f updating documentation
Damien Pacaud authored
14 * [SendTemplate](https://mandrillapp.com/api/docs/messages.JSON.html#method=send-template)
f997d91 @dpacaud Adding Readme for GitHub
authored
15
16
0a6773e @serty2 Update Readme.md
serty2 authored
17 Installation
18 -------
19
20 Upon install, this plugin adds a section to your Config.groovy file
21
22 mandrill {
23 apiKey = ""
24 // insert proxy values if needed
25 //proxy {
26 // host = ""
27 // The port Value has to be an integer ;)
28 // port = ""
29 //}
30 }
31
b0a051f updating documentation
Damien Pacaud authored
32 You need to fill in the apiKey parameter with the REST api KEY that you get with your [mandrill account](http://www.mandrill.com)
0a6773e @serty2 Update Readme.md
serty2 authored
33
f997d91 @dpacaud Adding Readme for GitHub
authored
34 Usage
35 -------
36
0a6773e @serty2 Update Readme.md
serty2 authored
37 Inject MandrillService into your services or controllers :
38
39 def mandrillService
40
41 ### Ping
42
43 To call the ping method just type :
44
45 def ret = mandrillService.ping()
46
47 ret should contain "PONG!"
48
49 ### Info
50
51 To call the ping method just type :
b0a051f updating documentation
Damien Pacaud authored
52
0a6773e @serty2 Update Readme.md
serty2 authored
53 def ret = mandrillService.info()
54
55 ret should contain a JSON array with the infos associated to your mandrill API Key
56
57
58 ### Send
59
b0a051f updating documentation
Damien Pacaud authored
60 To send a text mail :
61
0a6773e @serty2 Update Readme.md
serty2 authored
62 def recpts = []
63 recpts.add(new MandrillRecipient(name:"foo", email:"foo@bar.com"))
64 recpts.add(new MandrillRecipient(name:"bar", email:"bar@foo.com"))
65 def message = new MandrillMessage(
66 text:"this is a text message",
67 subject:"this is a subject",
68 from_email:"thisisatest@yopmail.com",
b0a051f updating documentation
Damien Pacaud authored
69 to:recpts)
0a6773e @serty2 Update Readme.md
serty2 authored
70 message.tags.add("test")
71 def ret = mandrillService.send(message)
72
e26891a @Jimbo1167 Update README with SendResponse information.
Jimbo1167 authored
73 send will return a SendResponse Object with success or error information
b0a051f updating documentation
Damien Pacaud authored
74
75 To send an HTML mail :
76
77 def recpts = []
78 recpts.add(new MandrillRecipient(name:"foo", email:"foo@bar.com"))
79 recpts.add(new MandrillRecipient(name:"bar", email:"bar@foo.com"))
80 def message = new MandrillMessage(
81 html:"<html><body>this is an<b>html</b> message</body></html>",
82 subject:"this is a subject",
83 from_email:"thisisatest@yopmail.com",
84 to:recpts)
85 message.tags.add("test")
86 def ret = mandrillService.send(message)
87
e26891a @Jimbo1167 Update README with SendResponse information.
Jimbo1167 authored
88 send will return SendResponse Object with success or error information
b0a051f updating documentation
Damien Pacaud authored
89
90 ### SendTemplate
91
92 To send a mail using template :
93
94 def recpts = []
95 recpts.add(new MandrillRecipient(name:"foo", email:"foo@bar.com"))
96 recpts.add(new MandrillRecipient(name:"bar", email:"bar@foo.com"))
97 def contents = []
98 contents.add([name:"test name", content:"test content"])
99 def message = new MandrillMessage(
100 text:"this is a text message",
101 subject:"this is a subject",
102 from_email:"thisisatest@yopmail.com",
103 to:recpts)
104 message.tags.add("test")
105 def ret = mandrillService.sendTemplate(message, "templateName", contens )
e26891a @Jimbo1167 Update README with SendResponse information.
Jimbo1167 authored
106
107 ### SendResponse
108 Per the [Mandrill API](https://mandrillapp.com/api/docs/messages.JSON.html#example-response-send) send calls will respond with:
109
110 Example Response JSON
111 [
112 {
113 "email": "recipient.email@example.com",
114 "status": "sent",
115 "reject_reason": "hard-bounce",
116 "_id": "abc123abc123abc123abc123abc123"
117 }
118 ]
119
120 Example Error Response JSON
121 [
122 {
123 "status": "error",
124 "code": 12,
125 "name": "Unknown_Subaccount",
126 "message": "No subaccount exists with the id 'customer-123'"
127 }
128 ]
129
130 These fields will be accessible via a SendResponse object:
131
132 def ret = mandrillService.sendTemplate(message, "templateName", contens )
133 if (ret.success) {
134 // do successful things
135 } else {
136 log.error("Error sending email: status: $ret.status rejectReason: $ret.rejectReason, message: $ret.message")
137 }
138 Note: success is derived from status being either 'sent', 'queued', or 'scheduled'
d81b6af adding contributors to readme
Damien Pacaud authored
139
140
141 ### Contributors
142
3ed8f71 adding new contributor
Damien Pacaud authored
143 Thanks to [James Schindler](https://github.com/Jimbo1167), [gaganc](https://github.com/gaganc) and [cympak2](https://github.com/cympak2) for their contributions
Something went wrong with that request. Please try again.