mailjet 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,42 @@
1
+ Copyright 2012 Benezech
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
22
+
23
+ Copyright (c) 2011 Holinnn
24
+
25
+ Permission is hereby granted, free of charge, to any person obtaining
26
+ a copy of this software and associated documentation files (the
27
+ "Software"), to deal in the Software without restriction, including
28
+ without limitation the rights to use, copy, modify, merge, publish,
29
+ distribute, sublicense, and/or sell copies of the Software, and to
30
+ permit persons to whom the Software is furnished to do so, subject to
31
+ the following conditions:
32
+
33
+ The above copyright notice and this permission notice shall be
34
+ included in all copies or substantial portions of the Software.
35
+
36
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
37
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
38
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
39
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
40
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
41
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
42
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,457 @@
1
+ # Mailjet
2
+
3
+ [Maijet][mailjet]'s official Ruby wrapper, bootstraped with [Mailjetter][mailjetter].
4
+
5
+ <!--
6
+
7
+ [![Build Status](https://secure.travis-ci.org/jbescoyez/mailjet.png?branch=master)][travis]
8
+ [![Dependency Status](https://gemnasium.com/jbescoyez/mailjet.png)][gemnasium]
9
+ [![Maintainance status](http://stillmaintained.com/jbescoyez/mailjet.png)][stillmaintained]
10
+
11
+ -->
12
+
13
+ [travis]: http://travis-ci.org/jbescoyez/mailjet
14
+ [gemnasium]: https://gemnasium.com/jbescoyez/mailjet
15
+ [stillmaintained]: http://stillmaintained.com/jbescoyez/mailjet
16
+ [mailjet]: http://www.mailjet.com
17
+ [rubinius]: http://rubini.us/
18
+ [ree]: http://www.rubyenterpriseedition.com/
19
+ [jruby]:http://jruby.org/
20
+ [mailjetter]:https://github.com/holinnn/mailjetter/
21
+
22
+ <!-- You can read this readme file in other languages:
23
+ english | [french](./README.fr.md) -->
24
+
25
+ This gem helps you to:
26
+
27
+ * Send transactional emails through Mailjet API in Rails 3
28
+ * Manage your lists, contacts and campaigns
29
+ * Track email delivery through event API
30
+
31
+ Compatibility:
32
+
33
+ - Ruby 1.8.7
34
+ - Ruby 1.9.X
35
+ - [jRuby][jruby]
36
+ - [Rubinius][rubinius]
37
+
38
+ Rails ActionMailer integration designed for Rails 3.X
39
+
40
+ ## Install
41
+
42
+ ### Bundler
43
+
44
+ Add the following in your Gemfile:
45
+
46
+ ```ruby
47
+ # Gemfile
48
+
49
+ gem 'mailjet'
50
+ ```
51
+
52
+ and let the bundler magic happen
53
+
54
+ ```bash
55
+ $ bundle install
56
+ ```
57
+
58
+ ### Rubygems
59
+
60
+ ```bash
61
+ $ gem install mailjet
62
+ ```
63
+
64
+ ## Setup
65
+
66
+ ### Api key
67
+
68
+ You need a proper account with [Maijet][mailjet]. You can get the API key through the [Maijet][mailjet] interface in _Account/Master API key_
69
+
70
+ Add the keys to an initializer:
71
+
72
+ ```ruby
73
+ # initializers/mailjet.rb
74
+ Mailjet.configure do |config|
75
+ config.api_key = 'your-api-key'
76
+ config.secret_key = 'your-secret-key'
77
+ config.domain = 'my_domain.com'
78
+ config.default_from = 'my_regitered_mailjet_email@domain.com'
79
+ end
80
+ ```
81
+
82
+ `domain` is needed if you send emails with :mailjet's SMTP (below)
83
+
84
+ `default_from` is optional if you send emails with :mailjet's SMTP (below)
85
+
86
+ ### Send emails with ActionMailer
87
+
88
+ As easy as:
89
+
90
+ ```ruby
91
+ # application.rb
92
+ config.action_mailer.delivery_method = :mailjet
93
+
94
+ ```
95
+
96
+ ## Manage your campaigns
97
+
98
+ ### Contacts
99
+
100
+ #### Filter your contacts
101
+
102
+ ```ruby
103
+ > contacts = Mailjet::Contact.all(status: 'active', start: 100, limit: 2)
104
+ => [#<Mailjet::Contact>, #<Mailjet::Contact>]
105
+ > contacts = Mailjet::Contact.all(openers: true, start: 100, limit: 2)
106
+ => [#<Mailjet::Contact>, #<Mailjet::Contact>]
107
+ ```
108
+
109
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/contact/list*
110
+ *All parameters and attributes for the openers option at https://eu.mailjet.com/docs/api/contact/openers*
111
+
112
+ #### More info about your contacts
113
+
114
+ ```ruby
115
+ > contacts[0].infos
116
+ => {blocked: 12, click: 1, email: 'test@mailjet.com'}
117
+ ```
118
+
119
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/contact/infos*
120
+
121
+ ### Lists
122
+
123
+ #### Create a new list
124
+
125
+ ```ruby
126
+ > list = Mailjet::List.create(label: 'My Mailjet list', name: "mymailjetlist")
127
+ ```
128
+
129
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/create*
130
+
131
+ #### List your lists
132
+
133
+ ```ruby
134
+ > Mailjet::List.all(limit: 10, start: 0, orderby: 'id ASC')
135
+ ```
136
+
137
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/all*
138
+
139
+ #### Update a list
140
+
141
+ ```ruby
142
+ > list = Mailjet::List.all.find{|l| l.name == 'mymailjetlist' }
143
+ > list = list.update(label: 'My updated Mailjet list', name: "myupdatedmailjetlist")
144
+ ```
145
+
146
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/update*
147
+
148
+ #### Show all contacts within a list
149
+
150
+ ```ruby
151
+ > list.contacts
152
+ => [#<Mailjet::Contact>, #<Mailjet::Contact>]
153
+ ```
154
+
155
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/contacts*
156
+
157
+ #### Add contacts to your list
158
+
159
+ ```ruby
160
+ > list.add_contacts("test@mailjet.com", "test2@mailjet.com", force: true )
161
+ => OK
162
+ ```
163
+
164
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/addmanycontacts*
165
+
166
+ #### Remove contacts from a list
167
+
168
+ ```ruby
169
+ > list.remove_contacts("test@mailjet.com", "test2@mailjet.com")
170
+ => OK
171
+ ```
172
+
173
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/removemanycontacts*
174
+
175
+ #### Direct list email
176
+
177
+ ```ruby
178
+ > list.email
179
+ => "jk324jlO3N32203@lists.mailjet.com"
180
+ ```
181
+
182
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/email*
183
+
184
+
185
+ #### Get statistics
186
+
187
+ ```ruby
188
+ > list.statistics
189
+ => {active: 20, bounce: 1, click: 14, created_at: "2012-02-02 21:59:59", ...}
190
+ ```
191
+
192
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/statistics*
193
+
194
+ #### Delete a list
195
+
196
+ ```ruby
197
+ > list.delete
198
+ => OK
199
+ ```
200
+
201
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/lists/delete*
202
+
203
+ ### Campaigns
204
+
205
+ #### Create a new campaign:
206
+
207
+ ```ruby
208
+ > campaign = Mailjet::Campaign.create(title: "My Mailjet Campaign", list_id: Mailjet::List.all.first.id, from: "mailjet-registered-email@domain.com", from_name: "Sender Name", subject: "Our new product", lang: "en", footer: "default")
209
+ ```
210
+
211
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/createcampaign*
212
+
213
+ #### List your campaigns:
214
+
215
+ ```ruby
216
+ > campaigns = Mailjet::Campaign.all(start: 10, limit: 20)
217
+ => [#<Mailjet::Campaign>, #<Mailjet::Campaign>, ...]
218
+ ```
219
+
220
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/campaigns*
221
+
222
+ #### Find one campaign:
223
+
224
+ ```ruby
225
+ > campaigns = Mailjet::Campaign.find(19)
226
+ => #<Mailjet::Campaign>
227
+ ```
228
+
229
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/campaigns*
230
+
231
+ #### Update your campaign:
232
+
233
+ ```ruby
234
+ > campaign.update(title: "My *new* Mailjet Campaign")
235
+ ```
236
+
237
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/updatecampaign*
238
+
239
+ #### Get all the subscribers to your campaign:
240
+
241
+ ```ruby
242
+ > campaign.contacts(limit: 2, start: 0, status: 'queued')
243
+ => [#<Mailjet::Contact id: 123, email: 'test@mailjet.com', sent_at: "2012-02-02 21:59:59", status: 'queued'>, #<Mailjet::Contact id: 456, email: 'test2@mailjet.com', sent_at: "2012-02-02 23:13:02", status: 'queued'>]
244
+ ```
245
+
246
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/contacts*
247
+
248
+ #### Send the campaign the associated contacts:
249
+
250
+ ```ruby
251
+ > campaign.send!
252
+ => OK
253
+ ```
254
+
255
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/sendcampaign*
256
+
257
+ #### Send a test email to specified email address:
258
+
259
+ ```ruby
260
+ > campaign.test('test@mailjet.com')
261
+ => OK # response status
262
+ ```
263
+
264
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/testcampaign*
265
+
266
+ #### Get statistics:
267
+
268
+ ```ruby
269
+ > campaign.statistics
270
+ => { total: 200, bounce: 1, bounce_pct: 0.5, click: 10, click_pct: 5, open: 20, open_pct: 10, sent: 200, sent_pct: 100, spam: 1, spam_pct: 0.5, total: 200 }
271
+ ```
272
+
273
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/statistics*
274
+
275
+ #### Template categories:
276
+
277
+ ```ruby
278
+ > Mailjet::TemplateCategory.all
279
+ => [#<Mailjet::TemplateCategory id: 2, label: "basic", value: "Basic">, #<Mailjet::TemplateCategory id: 6, label: "design", value: "Design">]
280
+ ```
281
+
282
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/tplcategories*
283
+
284
+ #### Template models:
285
+
286
+ ```ruby
287
+ > Mailjet::TemplateModel.all(category: 2, custom: true, locale: 'fr_FR')
288
+ => [<#Mailjet::TemplateModel id: 4, name: "Text", header_link: "http:\/\/" ... ]
289
+ ```
290
+
291
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/tplmodels*
292
+
293
+ #### Get the raw HTML form a campaign:
294
+
295
+ ```ruby
296
+ > campaign.html
297
+ => "<html><head></head><body>Test</body></html>"
298
+ ```
299
+
300
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/htmlcampaign*
301
+
302
+ #### Duplicate a campaign:
303
+
304
+ ```ruby
305
+ > new_campaign = campaign.duplicate(title: "Another Mailjet Campaign")
306
+ => #<Mailjet::Campaign title: "Another Mailjet Campaign" ... >
307
+ ```
308
+
309
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/message/duplicatecampaign*
310
+
311
+ ### Reporting
312
+
313
+ #### Get the list of all your clicks
314
+
315
+ ```ruby
316
+ > clicks = Mailjet::Reporting.clicks(from: "test@domain.com")
317
+ => [<#Mailjet::Click id: 4, click_delay: 1234, date: "2012-02-08", link: "", user_agent: "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0"} ]
318
+ > clicks.first.contact
319
+ => #<Mailjet::Contact id: 123, email: "test@mailjet.com">
320
+ ```
321
+
322
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/report/click*
323
+
324
+ #### Info about domains your emails are sent to
325
+
326
+ ```ruby
327
+ > Mailjet::Reporting.domains(start: 3, limit: 6)
328
+ => [{bounce_rate: 0.1, clicked_rate: 0.2, ...}, {bounce_rate: 0.8, clicked_rate: 0.1, ...}]
329
+ ```
330
+
331
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/report/domain*
332
+
333
+ #### Clients used to open emails
334
+
335
+ ```ruby
336
+ > Mailjet::Reporting.clients(start: 3, limit: 6)
337
+ => [{client: "Gmail", open_rate: 0.1, platform: "Windows", ...}, {client: "Outlook", open_rate: 0.3, platform: "Windows", ...}]
338
+ ```
339
+
340
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/report/emailclients*
341
+
342
+ #### Info about email sent
343
+
344
+ ```ruby
345
+ > Mailjet::Reporting.emails(from_domain: "domain.com", limit: 10)
346
+ => [#<Mailjet::Email>, #<Mailjet::Email>, #<Mailjet::Email>, ...]
347
+ ```
348
+
349
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/report/emailsent*
350
+
351
+ #### Global stats about a set of emails
352
+
353
+ ```ruby
354
+ > Mailjet::Reporting.statistics(from_domain: "domain.com", limit: 10)
355
+ => { avg_clicked_delay: 123, avg_opened_rate: 0.432, blocked: 13, ...}
356
+ ```
357
+
358
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/report/emailstatistics*
359
+
360
+
361
+ #### Opened email Geolocation
362
+
363
+ ```ruby
364
+ > Mailjet::Reporting.geolocation(from_domain: "domain.com", limit: 10)
365
+ => [{click: 123, country: "France", open: 234}, {click: 9876, country: "US", open: 12345}]
366
+ ```
367
+
368
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/report/geoip*
369
+
370
+ #### User-Agents used to open emails
371
+
372
+ ```ruby
373
+ > Mailjet::Reporting.agents(start: 3, limit: 6)
374
+ => [{cnt_clicked: 123, part: 30, platform: "Windows", user_agent: "Mozilla/5.0 (Windows NT 5.1; rv:5.0) Gecko/20100101 Firefox/5.0"}, ...]
375
+ ```
376
+
377
+ *All parameters and attributes at https://eu.mailjet.com/docs/api/report/useragents*
378
+
379
+ ## Track email delivery
380
+
381
+ You can setup your Rack application in order to receive feedback on emails you sent (clicks, etc.)
382
+
383
+ First notify Mailjet of your desired endpoint (say: 'http://www.my_domain.com/mailjet/callback') at https://www.mailjet.com/account/triggers
384
+
385
+ Then configure Mailjet's Rack application to catch these callbacks.
386
+
387
+ A typical Rails/ActiveRecord installation would look like that:
388
+
389
+ ```ruby
390
+ # application.rb
391
+
392
+ config.middleware.use Mailjet::Rack::Endpoint, '/mailjet/callback' do |params| # using the same URL you just set in Mailjet's administration
393
+
394
+ email = params['email'].presence || params['original_address'] # original_address is for typofix events
395
+
396
+ if user = User.find_by_email(email)
397
+ user.process_email_callback(params)
398
+ else
399
+ Rails.logger.fatal "[Mailjet] User not found: #{email} -- DUMP #{params.inspect}"
400
+ end
401
+ end
402
+
403
+ # user.rb
404
+ class User < ActiveRecord::Base
405
+
406
+ def process_email_callback(params)
407
+
408
+ # Returned events and options are described at https://eu.mailjet.com/docs/event_tracking
409
+ case params['event']
410
+ when 'open'
411
+ # Mailjet's invisible pixel was downloaded: user allowed for images to be seen
412
+ when 'click'
413
+ # a link (tracked by Mailjet) was clicked
414
+ when 'bounce'
415
+ # is user's email valid? Recipient not found
416
+ when 'spam'
417
+ # gateway or user flagged you
418
+ when 'blocked'
419
+ # gateway or user blocked you
420
+ when 'typofix'
421
+ # email routed from params['original_address'] to params['new_address']
422
+ else
423
+ Rails.logger.fatal "[Mailjet] Unknown event #{params['event']} for User #{self.inspect} -- DUMP #{params.inspect}"
424
+ end
425
+ end
426
+ ```
427
+
428
+ Note that since it's a Rack application, any Ruby Rack framework (say: Sinatra, Padrino, etc.) is compatible.
429
+
430
+ ## Testing
431
+
432
+ For maximum reliability, the gem is tested against Mailjet's server for some parts, which means that valid credentials are needed.
433
+ Do NOT use your production account (create a new one if needed), because some tests are destructive.
434
+
435
+ ```yml
436
+ # GEM_ROOT/config.yml
437
+ mailjet:
438
+ api_key: YOUR_API_KEY
439
+ secret_key: YOUR_SECRET_KEY
440
+ default_from: YOUR_REGISTERED_SENDER_EMAIL # the email you used to create the account should do it
441
+ ```
442
+
443
+ Then at the root of the gem, simply run:
444
+
445
+ ```bash
446
+ bundle
447
+ rake
448
+ ```
449
+ ## Send a pull request
450
+
451
+ - Fork the project.
452
+ - Create a topic branch.
453
+ - Implement your feature or bug fix.
454
+ - Add documentation for your feature or bug fix.
455
+ - Add specs for your feature or bug fix.
456
+ - Commit and push your changes.
457
+ - Submit a pull request. Please do not include changes to the gemspec, or version file.