multi_mail 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fcb39c73b30d0f52705ccc4d3f24bcb1142a974d
4
- data.tar.gz: c1a3e5183e6755f559475f3a4dcda2f8103d89fb
3
+ metadata.gz: a14ecc758499e8df176c767f62299f37df33cb18
4
+ data.tar.gz: 32b938fec60cb8e6ae4b458bc5e88ccdcfd5237f
5
5
  SHA512:
6
- metadata.gz: b93ac384cfad8aa761a4cf21073a1c5ac4379493be11e8823f82006b8b8f2500e0868a5a1f545c09f22ecde04e107ec54d3cba42aaedfbb6f27a03e6f7f84196
7
- data.tar.gz: f850d3ba49bc77ba05a54d0851920495bfa8ae4030d5a6f574d436009b6a115032b3e1ac5bccf0e59251ce379425ca6161713b6a6c12733598069628662dfffd
6
+ metadata.gz: 00473360787d54704565c3c4be5c25af31e27254fc64495ea229e59d934a64f8a645bd43b0687a39ebba94f5b488a0aa76192aee6c6b24b5384a79c4d501fa10
7
+ data.tar.gz: 7b43f573c40d70d6eab2f2a5f5fc2456f3b3cff2941701f2ec748ee1a8b509806a8828f230ae2dfaddc93da0f9e777487bad7da586084c685c0e3078d419ee6e
data/.gitignore CHANGED
@@ -4,5 +4,4 @@
4
4
  Gemfile.lock
5
5
  doc/*
6
6
  pkg/*
7
- spec/cassettes
8
7
  api_keys.yml
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,10 +1,9 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.2
5
3
  - 1.9.3
6
4
  - 2.0.0
7
- - ree
5
+ - 2.1.0
6
+ - 2.2.0
8
7
  env:
9
8
  global:
10
9
  # MAILGUN_API_KEY
data/.yardopts CHANGED
@@ -1,4 +1,3 @@
1
- --no-private
2
1
  --hide-void-return
3
2
  --embed-mixin ClassMethods
4
3
  --markup=markdown
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in the gemspec
4
4
  gemspec
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2012 Open North Inc.
1
+ Copyright (c) 2012 James McKinney
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
- # MultiMail: easily switch email APIs
1
+ # MultiMail: Easily switch email APIs
2
2
 
3
- [![Build Status](https://secure.travis-ci.org/opennorth/multi_mail.png)](http://travis-ci.org/opennorth/multi_mail)
4
- [![Dependency Status](https://gemnasium.com/opennorth/multi_mail.png)](https://gemnasium.com/opennorth/multi_mail)
5
- [![Coverage Status](https://coveralls.io/repos/opennorth/multi_mail/badge.png?branch=master)](https://coveralls.io/r/opennorth/multi_mail)
6
- [![Code Climate](https://codeclimate.com/github/opennorth/multi_mail.png)](https://codeclimate.com/github/opennorth/multi_mail)
3
+ [![Gem Version](https://badge.fury.io/rb/multi_mail.svg)](https://badge.fury.io/rb/multi_mail)
4
+ [![Build Status](https://secure.travis-ci.org/jpmckinney/multi_mail.png)](https://travis-ci.org/jpmckinney/multi_mail)
5
+ [![Dependency Status](https://gemnasium.com/jpmckinney/multi_mail.png)](https://gemnasium.com/jpmckinney/multi_mail)
6
+ [![Coverage Status](https://coveralls.io/repos/jpmckinney/multi_mail/badge.png)](https://coveralls.io/r/jpmckinney/multi_mail)
7
+ [![Code Climate](https://codeclimate.com/github/jpmckinney/multi_mail.png)](https://codeclimate.com/github/jpmckinney/multi_mail)
7
8
 
8
9
  Many providers offer APIs to send, receive, and parse email. MultiMail lets you easily switch between these APIs, and integrates tightly with the [Mail](https://github.com/mikel/mail) gem.
9
10
 
@@ -12,7 +13,7 @@ Many providers offer APIs to send, receive, and parse email. MultiMail lets you
12
13
  * [Mandrill](http://mandrill.com/): [Example](#mandrill)
13
14
  * [Postmark](http://postmarkapp.com/): [Example](#postmark)
14
15
  * [SendGrid](http://sendgrid.com/): [Example](#sendgrid)
15
- * MTA like [Postfix](http://en.wikipedia.org/wiki/Postfix_\(software\)) or [qmail](http://en.wikipedia.org/wiki/Qmail): [Example](#mta)
16
+ * MTA like [Postfix](https://en.wikipedia.org/wiki/Postfix_\(software\)) or [qmail](https://en.wikipedia.org/wiki/Qmail): [Example](#mta)
16
17
 
17
18
  ## Usage
18
19
 
@@ -30,7 +31,7 @@ messages = service.process(data)
30
31
 
31
32
  `messages` will be an array of [Mail::Message](https://github.com/mikel/mail) instances.
32
33
 
33
- Any non-standard parameters provided by an API are added to each message as a header. For example, Mailgun provides `stripped-text`, which is the message body without quoted parts or signature block. You can access it as `message['stripped-text'].value`.
34
+ Any non-standard parameters provided by an API are added to each message as an instance variable. For example, Mailgun provides `stripped-text`, which is the message body without quoted parts or signature block. You can access it as `message.stripped_text`. The instance variable is the non-standard parameter in lowercase with underscores instead of hyphens.
34
35
 
35
36
  ### Outgoing
36
37
 
@@ -41,7 +42,19 @@ require 'multi_mail'
41
42
 
42
43
  message = Mail.new do
43
44
  delivery_method MultiMail::Sender::Postmark, :api_key => 'your-api-key'
44
- ...
45
+
46
+ to 'user@wookiecookies.com'
47
+ from 'Chewbacca <chewy@wookiecookies.com>'
48
+ subject 'How About Some Cookies?'
49
+
50
+ text_part do
51
+ body 'I am just some plain text!'
52
+ end
53
+
54
+ html_part do
55
+ content_type 'text/html; charset=UTF-8'
56
+ body '<html><body><h1>I am a header</h1><p>And I am a paragraph</p></body></html>'
57
+ end
45
58
  end
46
59
 
47
60
  message.deliver
@@ -51,7 +64,18 @@ Alternatively, instead of setting `delivery_method` during initialization, you c
51
64
 
52
65
  ```ruby
53
66
  message = Mail.new do
54
- ...
67
+ to 'user@wookiecookies.com'
68
+ from 'Chewbacca <chewy@wookiecookies.com>'
69
+ subject 'How About Some Cookies?'
70
+
71
+ text_part do
72
+ body 'I am just some plain text!'
73
+ end
74
+
75
+ html_part do
76
+ content_type 'text/html; charset=UTF-8'
77
+ body '<html><body><h1>I am a header</h1><p>And I am a paragraph</p></body></html>'
78
+ end
55
79
  end
56
80
 
57
81
  message.delivery_method MultiMail::Sender::Postmark, :api_key => 'your-api-key'
@@ -67,6 +91,78 @@ Mail.defaults do
67
91
  end
68
92
  ```
69
93
 
94
+ #### ActionMailer
95
+
96
+ First, add the delivery method to ActionMailer:
97
+
98
+ ```
99
+ ActionMailer::Base.add_delivery_method :postmark, MultiMail::Sender::Postmark, :api_key => 'your-api-key'
100
+ ```
101
+
102
+ Set the default delivery method for all ActionMailer classes in `config/environments/<ENV>.rb`:
103
+
104
+ ```
105
+ config.action_mailer.delivery_method = :postmark
106
+ ```
107
+
108
+ Or, set the delivery method in an ActionMailer class:
109
+
110
+ ```
111
+ class UserMailer < ActionMailer::Base
112
+ default :delivery_method => :postmark
113
+ end
114
+ ```
115
+
116
+ Or, set the delivery method in an ActionMailer method:
117
+
118
+ ```
119
+ class UserMailer < ActionMailer::Base
120
+ def welcome_email(user)
121
+ mail({
122
+ :to => user.email,
123
+ :subject => 'Welcome to My Awesome Site',
124
+ :delivery_method => :postmark,
125
+ })
126
+ end
127
+ end
128
+ ```
129
+
130
+ Set the delivery method's default options for all ActionMailer classes in `config/environments/<ENV>.rb`:
131
+
132
+ ```
133
+ config.action_mailer.postmark_settings = {:api_key => 'your-api-key'}
134
+ ```
135
+
136
+ Or, set the delivery method's options in an ActionMailer method:
137
+
138
+ ```
139
+ class UserMailer < ActionMailer::Base
140
+ def welcome_email(mail)
141
+ mail({
142
+ :to => user.email,
143
+ :subject => 'Welcome to My Awesome Site',
144
+ :delivery_method_options => {:api_key => 'your-api-key'},
145
+ })
146
+ end
147
+ end
148
+ ```
149
+
150
+ Or, set the delivery method's options in an ActionMailer action:
151
+
152
+ ```
153
+ class UserMailer < ActionMailer::Base
154
+ after_action :set_delivery_method_options
155
+
156
+ ...
157
+
158
+ private
159
+
160
+ def set_delivery_method_options
161
+ mail.delivery_method.settings.merge!({:api_key => 'your-api-key'})
162
+ end
163
+ end
164
+ ```
165
+
70
166
  #### Tagging
71
167
 
72
168
  Mailgun, Mandrill and Postmark allow you to tag messages in order to accumulate statistics by tag, which will be accessible through their user interface:
@@ -90,19 +186,19 @@ Mailgun accepts at most [3 tags](http://documentation.mailgun.com/user_manual.ht
90
186
 
91
187
  #### Track opens and clicks
92
188
 
93
- Mailgun and Mandrill allow you to set open tracking and click tracking on a per-message basis:
189
+ Mailgun, Mandrill and Postmark allow you to set open tracking, and Mailgun and Mandrill allow you to set click tracking on a per-message basis:
94
190
 
95
191
  ```ruby
96
192
  require 'multi_mail'
97
193
 
98
194
  message = Mail.new do
99
195
  delivery_method MultiMail::Sender::Mailgun,
100
- :api_key => 'your-api-key',
101
- :domain => 'your-domain.mailgun.org',
102
- :track => {
103
- :opens => true,
104
- :clicks => false,
105
- }
196
+ :api_key => 'your-api-key',
197
+ :domain => 'your-domain.mailgun.org',
198
+ :track => {
199
+ :opens => true,
200
+ :clicks => false,
201
+ }
106
202
  ...
107
203
  end
108
204
 
@@ -200,7 +296,19 @@ See [Mailgun's documentation](http://documentation.mailgun.net/user_manual.html#
200
296
  ```ruby
201
297
  Mail.deliver do
202
298
  delivery_method MultiMail::Sender::Mailgun, :api_key => 'your-api-key', :domain => 'your-domain.mailgun.org'
203
- ...
299
+
300
+ to _to_
301
+ from _from_
302
+ subject _subject_
303
+
304
+ text_part do
305
+ body _text_
306
+ end
307
+
308
+ html_part do
309
+ content_type 'text/html; charset=UTF-8'
310
+ body _html_
311
+ end
204
312
  end
205
313
  ```
206
314
 
@@ -213,6 +321,14 @@ You may pass additional arguments to `delivery_method` to use Mailgun-specific f
213
321
  * `o:tracking`
214
322
  * `v:`
215
323
 
324
+ ```ruby
325
+ Mail.deliver do
326
+ delivery_method MultiMail::Sender::Mailgun, :api_key => 'your-api-key', :domain => 'your-domain.mailgun.org',
327
+ :o:campaign => 'campaign', :o:dkim => 'yes (or no)',...
328
+ ...
329
+ end
330
+ ```
331
+
216
332
  ## Mandrill
217
333
 
218
334
  ### Incoming
@@ -256,7 +372,19 @@ See [Mandrill's documentation](http://help.mandrill.com/entries/22092308-What-is
256
372
  ```ruby
257
373
  Mail.deliver do
258
374
  delivery_method MultiMail::Sender::Mandrill, :api_key => 'your-api-key'
259
- ...
375
+
376
+ to _to_
377
+ from _from_email_ + _from_name_
378
+ subject _subject_
379
+
380
+ text_part do
381
+ body _text_
382
+ end
383
+
384
+ html_part do
385
+ content_type 'text/html; charset=UTF-8'
386
+ body _html_
387
+ end
260
388
  end
261
389
  ```
262
390
 
@@ -275,6 +403,16 @@ You may pass additional arguments to `delivery_method` to use Mandrill-specific
275
403
  * `async`
276
404
  * `ip_pool`
277
405
  * `send_at`
406
+ * `template_name`
407
+ * `template_content`
408
+
409
+ ```ruby
410
+ Mail.deliver do
411
+ delivery_method MultiMail::Sender::Mandrill, :api_key => 'your-api-key',
412
+ :async => true, :ip_pool => 'main_pool', ...
413
+ ...
414
+ end
415
+ ```
278
416
 
279
417
  ## Postmark
280
418
 
@@ -296,7 +434,19 @@ See [Postmark's documentation](http://developer.postmarkapp.com/developer-inboun
296
434
  ```ruby
297
435
  Mail.deliver do
298
436
  delivery_method MultiMail::Sender::Postmark, :api_key => 'your-api-key'
299
- ...
437
+
438
+ to _To_
439
+ from _From_
440
+ subject _Subject_
441
+
442
+ text_part do
443
+ body _TextBody_
444
+ end
445
+
446
+ html_part do
447
+ content_type 'text/html; charset=UTF-8'
448
+ body _HtmlBody_
449
+ end
300
450
  end
301
451
  ```
302
452
 
@@ -331,12 +481,33 @@ See [SendGrid's documentation](http://sendgrid.com/docs/API_Reference/Webhooks/p
331
481
  ```ruby
332
482
  Mail.deliver do
333
483
  delivery_method MultiMail::Sender::SendGrid, :api_user => 'username', :api_key => 'password'
334
- ...
484
+
485
+ to _to_
486
+ from _from_ + _fromname_
487
+ subject _subject_
488
+
489
+ text_part do
490
+ body _text_
491
+ end
492
+
493
+ html_part do
494
+ content_type 'text/html; charset=UTF-8'
495
+ body _html_
496
+ end
335
497
  end
336
498
  ```
337
499
 
338
500
  You may also pass a `x-smtpapi` option to `delivery_method` ([see SendGrid's documentation](http://sendgrid.com/docs/API_Reference/Web_API/mail.html)).
339
501
 
502
+ ```ruby
503
+ Mail.deliver do
504
+ delivery_method MultiMail::Sender::SendGrid, :api_user => 'username', :api_key => 'password',
505
+ :x-smtpapi => '{ "some_json" : "with_some_data" }'
506
+ ...
507
+ end
508
+ ```
509
+
510
+
340
511
  ## MTA
341
512
 
342
513
  ### Incoming
@@ -367,16 +538,6 @@ service = MultiMail::Receiver.new({
367
538
 
368
539
  It's recommended to use a secret key, to ensure that the requests are sent by Postfix and qmail and not by other sources on the internet.
369
540
 
370
- ## Bugs? Questions?
371
-
372
- This gem's main repository is on GitHub: [http://github.com/opennorth/multi_mail](http://github.com/opennorth/multi_mail), where your contributions, forks, bug reports, feature requests, and feedback are greatly welcomed.
373
-
374
- ## Acknowledgements
375
-
376
- This gem is developed by [Open North](http://www.opennorth.ca/) through a partnership with the [Participatory Politics Foundation](http://www.participatorypolitics.org/).
377
-
378
- ## Copyright
379
-
380
541
  This gem re-uses code from [fog](https://github.com/fog/fog), released under the MIT license.
381
542
 
382
- Copyright (c) 2012 Open North Inc., released under the MIT license
543
+ Copyright (c) 2012 James McKinney, released under the MIT license
data/lib/multi_mail.rb CHANGED
@@ -2,7 +2,6 @@ require 'base64'
2
2
  require 'cgi'
3
3
  require 'json'
4
4
  require 'openssl'
5
- require 'iconv' unless RUBY_VERSION >= '1.9'
6
5
 
7
6
  require 'faraday'
8
7
  require 'mail'
@@ -23,6 +22,8 @@ module MultiMail
23
22
  class InvalidAPIKey < InvalidRequest; end
24
23
  # Raise if a message is invalid.
25
24
  class InvalidMessage < InvalidRequest; end
25
+ # Raise if a message template is invalid.
26
+ class InvalidTemplate < InvalidRequest; end
26
27
 
27
28
  # Raise if a message header is invalid
28
29
  class InvalidHeader < InvalidMessage; end
@@ -60,7 +61,7 @@ module MultiMail
60
61
  #
61
62
  # @param [Mail::Message] message a message
62
63
  # @return [Boolean] whether a message is an autoresponse
63
- # @see https://github.com/opennorth/multi_mail/wiki/Detecting-autoresponders
64
+ # @see https://github.com/jpmckinney/multi_mail/wiki/Detecting-autoresponders
64
65
  def autoresponse?(message)
65
66
  !!(
66
67
  # If any of the following headers are present and have the given value.
@@ -106,6 +107,7 @@ require 'multi_mail/receiver'
106
107
  require 'multi_mail/message/base'
107
108
  require 'multi_mail/receiver/base'
108
109
  require 'multi_mail/sender/base'
110
+ require 'multi_mail/cloudmailin/message'
109
111
  require 'multi_mail/mailgun/message'
110
112
  require 'multi_mail/mailgun/sender'
111
113
  require 'multi_mail/mandrill/message'
@@ -0,0 +1,7 @@
1
+ module MultiMail
2
+ module Message
3
+ class Cloudmailin < MultiMail::Message::Base
4
+ attr_accessor :reply_plain, :spf_result
5
+ end
6
+ end
7
+ end
@@ -24,17 +24,17 @@ module MultiMail
24
24
  end
25
25
 
26
26
  # @param [Hash] params the content of Cloudmailin's webhook
27
- # @return [Array<Mail::Message>] messages
27
+ # @return [Array<MultiMail::Message::Cloudmailin>] messages
28
28
  # @see http://docs.cloudmailin.com/http_post_formats/multipart/
29
29
  # @see http://docs.cloudmailin.com/http_post_formats/json/
30
30
  # @see http://docs.cloudmailin.com/http_post_formats/raw/
31
31
  def transform(params)
32
32
  case @http_post_format
33
33
  when 'raw', '', nil
34
- message = self.class.condense(Mail.new(params['message']))
34
+ message = self.class.condense(MultiMail::Message::Cloudmailin.new(Mail.new(params['message'])))
35
35
 
36
36
  # Extra Cloudmailin parameters.
37
- message['spf-result'] = params['envelope']['spf']['result']
37
+ message.spf_result = params['envelope']['spf']['result']
38
38
 
39
39
  if @attachment_store
40
40
  params['attachments'].each do |_,attachment|
@@ -52,7 +52,7 @@ module MultiMail
52
52
  attachment_store = @attachment_store
53
53
  this = self
54
54
 
55
- message = Mail.new do
55
+ message = MultiMail::Message::Cloudmailin.new do
56
56
  headers headers
57
57
 
58
58
  text_part do
@@ -92,8 +92,8 @@ module MultiMail
92
92
 
93
93
  # Extra Cloudmailin parameters. The multipart format uses CRLF whereas
94
94
  # the JSON format uses LF. Normalize to LF.
95
- message['reply_plain'] = params['reply_plain'].gsub("\r\n", "\n")
96
- message['spf-result'] = params['envelope']['spf']['result']
95
+ message.reply_plain = params['reply_plain'].gsub("\r\n", "\n")
96
+ message.spf_result = params['envelope']['spf']['result']
97
97
 
98
98
  [message]
99
99
  else
@@ -104,7 +104,7 @@ module MultiMail
104
104
  # @param [Mail::Message] message a message
105
105
  # @return [Boolean] whether the message is spam
106
106
  def spam?(message)
107
- message['spf-result'] && message['spf-result'].value == 'fail'
107
+ message.spf_result == 'fail'
108
108
  end
109
109
  end
110
110
  end