postmark-rails 0.16.0 → 0.21.0

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
- SHA1:
3
- metadata.gz: 11103f47e603b5ae549757fb861bff414067ca90
4
- data.tar.gz: 862e1cb8268be1498a138440ba5abb63ea4a8045
2
+ SHA256:
3
+ metadata.gz: 13b5d927c9a95b15fca7756699014d8d7c6aad06ca2c89393f146d730e643503
4
+ data.tar.gz: 44a410c53c18648827593cdc549997ee30d8fcca0ae11e8c9ac2c0a274ce8deb
5
5
  SHA512:
6
- metadata.gz: eaf79340d2482125dd51cf6b380c5bc33aac14bb2718a46735bea798df0ef185a68ee94509129a011369014e4978588f3d2f0c39ba71aaa4162668b4dc745f20
7
- data.tar.gz: b260ee5d8aa82bcbd7492fb91a812faac8365dd18d0ae95ce4a2e6714ad9750964e7dba32c1a167b030b5f38a9460336f3cb06246dbfd739d268bf3611a6ff3c
6
+ metadata.gz: 7c779410e7e648223fe32a193ed602a2ee98c5050ec7fde4fa727e6c1090fa1757cb59dc9cf53a57bc6a9911f1579edf78fe945bdb9abf60e268c32ce6f9df95
7
+ data.tar.gz: 8c46978be1f750f5e088ee2d0ea2ca7b6d32d084611f05d5213387eb19db7a5526736bb6915a77bd9466b039121f1faf6d3f345d522ffbb509ea5fd28c7ffc4a
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ pkg
8
8
  .rvmrc
9
9
  Gemfile.lock
10
10
  gemfiles/*.lock
11
+ **/*.idea
data/.travis.yml CHANGED
@@ -1,10 +1,13 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 1.8.7
4
- - 1.9.3
5
3
  - 2.0.0
6
- - 2.1.9
7
- - 2.2.5
4
+ - 2.1.10
5
+ - 2.2.10
6
+ - 2.3.8
7
+ - 2.4.5
8
+ - 2.5.3
9
+ - 2.6.0
10
+ - 2.7.0
8
11
  script: bundle exec rake spec
9
12
  gemfile:
10
13
  - Gemfile
@@ -13,22 +16,68 @@ gemfile:
13
16
  - gemfiles/Gemfile.actionmailer-4.0.x
14
17
  - gemfiles/Gemfile.actionmailer-4.1.x
15
18
  - gemfiles/Gemfile.actionmailer-4.2.x
19
+ - gemfiles/Gemfile.actionmailer-5.0.x
20
+ - gemfiles/Gemfile.actionmailer-5.1.x
21
+ - gemfiles/Gemfile.actionmailer-5.2.x
22
+ - gemfiles/Gemfile.actionmailer-6.0.x
16
23
  matrix:
17
24
  exclude:
18
- - rvm: 1.8.7
19
- gemfile: Gemfile
20
- - rvm: 1.9.3
21
- gemfile: Gemfile
22
25
  - rvm: 2.0.0
23
26
  gemfile: Gemfile
24
- - rvm: 2.1.9
27
+ - rvm: 2.0.0
28
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
29
+ - rvm: 2.0.0
30
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
31
+ - rvm: 2.0.0
32
+ gemfile: gemfiles/Gemfile.actionmailer-5.2.x
33
+ - rvm: 2.0.0
34
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
35
+
36
+ - rvm: 2.1.10
25
37
  gemfile: Gemfile
26
- - rvm: 1.8.7
38
+ - rvm: 2.1.10
39
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
40
+ - rvm: 2.1.10
41
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
42
+ - rvm: 2.1.10
43
+ gemfile: gemfiles/Gemfile.actionmailer-5.2.x
44
+ - rvm: 2.1.10
45
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
46
+
47
+ - rvm: 2.2.10
48
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
49
+
50
+ - rvm: 2.3.8
51
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
52
+
53
+ - rvm: 2.4.5
54
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
55
+
56
+ - rvm: 2.5.3
57
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
58
+ - rvm: 2.5.3
59
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
60
+
61
+ - rvm: 2.6.0
62
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
63
+ - rvm: 2.6.0
64
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
65
+ - rvm: 2.6.0
66
+ gemfile: gemfiles/Gemfile.actionmailer-4.0.x
67
+ - rvm: 2.6.0
68
+ gemfile: gemfiles/Gemfile.actionmailer-4.1.x
69
+ - rvm: 2.6.0
70
+ gemfile: gemfiles/Gemfile.actionmailer-4.2.x
71
+
72
+ - rvm: 2.7.0
73
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
74
+ - rvm: 2.7.0
75
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
76
+ - rvm: 2.7.0
27
77
  gemfile: gemfiles/Gemfile.actionmailer-4.0.x
28
- - rvm: 1.8.7
78
+ - rvm: 2.7.0
29
79
  gemfile: gemfiles/Gemfile.actionmailer-4.1.x
30
- - rvm: 1.8.7
80
+ - rvm: 2.7.0
31
81
  gemfile: gemfiles/Gemfile.actionmailer-4.2.x
32
82
  before_install:
33
- - gem update --system
34
- - gem install bundler
83
+ - .travis/setup.sh
data/.travis/setup.sh ADDED
@@ -0,0 +1,13 @@
1
+ #!/bin/bash
2
+
3
+ set -eax
4
+
5
+ echo "Configuring Ruby and Bundler..."
6
+ echo "TRAVIS_RUBY_VERSION=${TRAVIS_RUBY_VERSION}"
7
+
8
+ if [[ "$TRAVIS_RUBY_VERSION" < "2.3" ]];
9
+ then
10
+ gem install bundler -v '< 2'
11
+ else
12
+ gem install bundler
13
+ fi
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,32 @@
1
1
  = Changelog
2
2
 
3
+ == 0.21.0
4
+
5
+ * Update minimum postmark gem dependency to avoid use of TLS v1
6
+
7
+ == 0.20.0
8
+
9
+ * Update the postmark gem dependency to 1.x
10
+ * Added support for Rails 6
11
+ * Dropped support for Ruby 1.8.7 and 1.9.3
12
+ * Added support for Ruby 2.7
13
+
14
+ == 0.19.0
15
+
16
+ * Update the postmark gem dependency to 1.15.x.
17
+ * Added support for templated mailers.
18
+ * Added source_code_uri to the gemspec.
19
+ * Tested against all stable versions of ActionMailer 3.0-5.2 and Ruby 1.8.7-2.6.0.
20
+
21
+ == 0.18.0
22
+
23
+ * Update the postmark gem dependency to 1.14.x.
24
+
25
+ == 0.17.0
26
+
27
+ * Add support for metadata.
28
+ * Update the postmark gem dependency to 1.13.x.
29
+
3
30
  == 0.16.0
4
31
 
5
32
  * Update the postmark gem dependency to 1.11.x.
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,18 @@
1
+ # Before you report an issue or submit a pull request
2
+
3
+ *If you are blocked or need help with Postmark, please [contact
4
+ Postmark Support](https://postmarkapp.com/contact)*. For other, non-urgent
5
+ cases you’re welcome to report a bug and/or contribute to this project. We will
6
+ make our best effort to review your contributions and triage any bug reports in
7
+ a timely fashion.
8
+
9
+ If you’d like to submit a pull request:
10
+
11
+ * Fork the project.
12
+ * Make your feature addition or bug fix.
13
+ * Add tests for it. This is important to prevent future regressions.
14
+ * Do not mess with rakefile, version, or history.
15
+ * Update the CHANGELOG, list your changes under Unreleased.
16
+ * Update the README if necessary.
17
+ * Write short, descriptive commit messages, following the format used in therepo.
18
+ * Send a pull request. Bonus points for topic branches.
data/README.md CHANGED
@@ -1,221 +1,93 @@
1
- # postmark-rails gem
1
+ <a href="https://postmarkapp.com">
2
+ <img src="postmark.png" alt="Postmark Logo" title="Postmark" width="120" height="120" align="right">
3
+ </a>
4
+
5
+ # Postmark Rails Gem
2
6
 
3
7
  [![Build Status](https://travis-ci.org/wildbit/postmark-rails.svg?branch=master)](https://travis-ci.org/wildbit/postmark-rails) [![Code Climate](https://codeclimate.com/github/wildbit/postmark-rails/badges/gpa.svg)](https://codeclimate.com/github/wildbit/postmark-rails)
8
+ [![License](http://img.shields.io/badge/license-MIT-blue.svg?style=flat)](http://www.opensource.org/licenses/MIT)
9
+ [![Gem Version](https://badge.fury.io/rb/postmark-rails.svg)](https://badge.fury.io/rb/postmark-rails)
4
10
 
5
- The Postmark Rails Gem is a drop-in plug-in for ActionMailer to send emails via [Postmark](https://postmarkapp.com), an email delivery service for web apps. The gem has been created for fast implementation and fully supports all of [Postmark’s features](https://postmarkapp.com/why).
11
+ [Postmark](https://postmarkapp.com) allows you to send your emails with high delivery rates.
12
+ It also includes detailed statistics. In addition, Postmark can parse incoming emails which are forwarded back to your application.
6
13
 
7
- ## Supported Rails Versions
14
+ The Postmark Rails Gem is a drop-in plug-in for ActionMailer to send emails via [Postmark](https://postmarkapp.com).
15
+ The gem has been created for fast implementation and fully supports all of [Postmark’s features](https://postmarkapp.com/why).
8
16
 
9
- * Rails 5.0
10
- * Rails 4.x
11
- * Rails 3.x
17
+ ## Usage
12
18
 
13
- For Rails 2.3 please take a look at [version 0.4](https://github.com/wildbit/postmark-rails/tree/v0.4.2). It may miss some new features, but receives all required bug fixes and other support if needed.
19
+ Please see the [wiki](https://github.com/wildbit/postmark-rails/wiki) for detailed instructions about library features.
20
+ For details about Postmark API in general, please check out [Postmark developer docs](https://postmarkapp.com/developer).
14
21
 
15
- ## Configuring your Rails application
16
-
17
- Add `postmark-rails` to your Gemfile (change version numbers if needed) and run `bundle install`.
18
-
19
- ``` ruby
20
- gem 'postmark-rails', '~> 0.15.0'
21
- ```
22
-
23
- Save your Postmark API token to [config/secrets.yml](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml).
22
+ ## Requirements
24
23
 
25
- ``` yaml
26
- postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
27
- ```
24
+ You will need a Postmark account, server and sender signature (or verified domain) set up to use it.
25
+ For details about setup, check out [wiki pages](https://github.com/wildbit/postmark-rails/wiki/Getting-Started).
28
26
 
29
- Set Postmark as your preferred mail delivery method via `config/application.rb`:
27
+ Also you will need a [postmark gem](https://github.com/wildbit/postmark-gem) version 1.0 and higher is required.
30
28
 
31
- ``` ruby
32
- config.action_mailer.delivery_method = :postmark
33
- config.action_mailer.postmark_settings = { :api_token => Rails.application.secrets.postmark_api_token }
34
- ```
29
+ ### Supported Rails Versions
35
30
 
36
- **Note**: The `postmark_settings` hash can contain [any options](https://github.com/wildbit/postmark-gem#communicating-with-the-api) supported by `Postmark::ApiClient`.
31
+ * Rails 6.0
32
+ * Rails 5.0
33
+ * Rails 4.x
34
+ * Rails 3.x
37
35
 
38
- ## Tracking opens and tagging your deliveries
36
+ For Rails 2.3 please take a look at [version 0.4](https://github.com/wildbit/postmark-rails/tree/v0.4.2).
37
+ It may miss some new features, but receives all required bug fixes and other support if needed.
39
38
 
40
- You can use tags to categorize outgoing messages and attach application-specific information. Tagging the different types of email that you send lets you [review statistics and bounce reports separately](http://developer.postmarkapp.com/developer-build.html#message-format).
39
+ ## Installation
41
40
 
42
- Pass `:track_opens => 'true'` to enable/disable open tracking on per-message basis. Check out the [Triggers API](https://github.com/wildbit/postmark-gem/wiki/The-Triggers-API-Support) to see how Postmark can help you control this with tags. **Note that we pass a string here, since it becomes a header value. Passing a boolean may or may not work depending on your Rails version.**
41
+ Add `postmark-rails` to your Gemfile and run `bundle install`.
43
42
 
44
43
  ``` ruby
45
- class TestMailer < ActionMailer::Base
46
-
47
- def tagged_message
48
- mail(
49
- :subject => 'hello',
50
- :to => 'sheldon@bigbangtheory.com',
51
- :from => 'leonard@bigbangtheory.com',
52
- :tag => 'my-tag',
53
- :track_opens => 'true'
54
- )
55
- end
56
-
57
- end
44
+ gem 'postmark-rails'
58
45
  ```
59
46
 
60
- ## Sending attachments
61
47
 
62
- You can also send file attachments with Postmark. Read our Developer docs for [additional information](http://developer.postmarkapp.com/developer-build.html#attachments).
63
48
 
64
- The Postmark gem is compatible with [ActionMailer attachments API](http://api.rubyonrails.org/classes/ActionMailer/Base.html#method-i-attachments). It allows you to specify the name, content-type and other attributes for your attachments.
49
+ ## Rails 6
50
+ Save your Postmark Server API Token to [config/credentials.yml.enc](https://guides.rubyonrails.org/security.html#custom-credentials):
65
51
 
66
- The legacy `:postmark_attachments` attribute is *no longer supported* on Rails 3.2.13 and above.
52
+ run `rails secret`, then run `rails credentials:edit` and add:
67
53
 
68
- ``` ruby
69
- class TestMailer < ActionMailer::Base
70
-
71
- def message_with_attachment
72
- attachments.inline['logo.png'] = File.read("/path/to/image") # Inline image
73
- attachments['42.jpg'] = File.read("/path/to/file") # Attached file
74
- mail(
75
- :subject => 'hello',
76
- :to => 'sheldon@bigbangtheory.com',
77
- :from => 'leonard@bigbangtheory.com'
78
- )
79
- end
80
-
81
- end
54
+ ``` yaml
55
+ postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
82
56
  ```
83
-
84
- ## Sending in batches
85
-
86
- While Postmark is focused on transactional email, we understand that developers
87
- with higher volumes or processing time constraints need to send their messages
88
- in batches. To facilitate this we provide a batching endpoint that permits you
89
- to send up to 500 well-formed Postmark messages in a single API call.
57
+ Set Postmark as your preferred mail delivery method via `config/application.rb`:
90
58
 
91
59
  ``` ruby
92
- client = Postmark::ApiClient.new('your-api-token')
93
-
94
- messages = []
95
- messages << DigestMailer.weekly_digest(@user1)
96
- messages << DigestMailer.weekly_digest(@user2)
97
-
98
- client.deliver_messages(messages)
99
-
100
- messages.first.delivered?
101
- # => true
102
-
103
- messages.all?(&:delivered)
104
- # => true
60
+ config.action_mailer.delivery_method = :postmark
61
+ config.action_mailer.postmark_settings = { api_token: Rails.application.credentials.postmark_api_token }
105
62
  ```
106
63
 
107
- ## Error handling
64
+ ## Rails 3-5
65
+ Save your Postmark Server API token to [config/secrets.yml](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml).
108
66
 
109
- The gem respects the `ActionMailer::Base.raise_delivery_errors` setting and will surpress any exceptions
110
- if it’s set to `false`. When delivery errors are enabled, the gem can raise any one of the exceptions
111
- listed in the [postmark](https://github.com/wildbit/postmark-gem#error-handling) gem docs.
112
-
113
-
114
- ### ActionMailer 5
115
-
116
- For ActionMailer 5 and above, use `ActionMailer::Base.rescue_from` to define handlers for
117
- each error you care about.
118
-
119
- #### Example
120
-
121
- ``` ruby
122
- class ApplicationMailer < ActionMailer::Base
123
- default from: 'user@example.org'
124
- layout 'mailer'
125
-
126
- rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
127
-
128
- private
129
-
130
- def postmark_client
131
- ::Postmark::ApiClient.new(ActionMailer::Base.postmark_settings[:api_token],
132
- ActionMailer::Base.postmark_settings.except(:api_token))
133
- end
134
-
135
-
136
- # This is just an example. Sometimes you might not want to reactivate
137
- # an address that hard bounced.
138
- # Warning: Having too many bounces can affect your delivery reputation
139
- # with email providers
140
- def reactivate_and_retry(error)
141
- Rails.logger.info("Error when sending #{message} to #{error.recipients.join(', ')}")
142
- Rails.logger.info(error)
143
-
144
- error.recipients.each do |recipient|
145
- bounce = postmark_client.bounces(emailFilter: recipient).first
146
- next unless bounce
147
- postmark_client.activate_bounce(bounce[:id])
148
- end
149
-
150
- # Try again immediately
151
- message.deliver
152
- end
153
- end
67
+ ``` yaml
68
+ postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
154
69
  ```
155
70
 
156
- ### ActionMailer 4 and below
157
-
158
- Wrap any calls to `#deliver_now` in error handlers like the one described
159
- in the [postmark](https://github.com/wildbit/postmark-gem#error-handling) gem
160
- docs.
161
-
162
- Rails 4.2 introduces `#deliver_later` but doesn’t support `rescue_from` for
163
- mailer classes. Instead, use the following monkey patch for
164
- `ActionMailer::DeliveryJob`.
71
+ Set Postmark as your preferred mail delivery method via `config/application.rb`:
165
72
 
166
73
  ``` ruby
167
- # app/mailers/application_mailer.rb
168
-
169
- class ApplicationMailer < ActionMailer::Base
170
- default from: 'user@example.org'
171
- end
172
-
173
- class ActionMailer::DeliveryJob
174
- rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
175
-
176
- def postmark_client
177
- ::Postmark::ApiClient.new(ActionMailer::Base.postmark_settings[:api_token],
178
- ActionMailer::Base.postmark_settings.except(:api_token))
179
- end
180
-
181
-
182
- # This is just an example. Sometimes you might not want to reactivate
183
- # an address that hard bounced.
184
- # Warning: Having too many bounces can affect your delivery reputation
185
- # with email providers
186
- def reactivate_and_retry(error)
187
- Rails.logger.info("Error when sending a message to #{error.recipients.join(', ')}")
188
- Rails.logger.info(error)
189
-
190
- error.recipients.each do |recipient|
191
- bounce = postmark_client.bounces(emailFilter: recipient).first
192
- next unless bounce
193
- postmark_client.activate_bounce(bounce[:id])
194
- end
195
-
196
- # Try again immediately
197
- perform(*arguments)
198
- end
199
- end
74
+ config.action_mailer.delivery_method = :postmark
75
+ config.action_mailer.postmark_settings = { :api_token => Rails.application.secrets.postmark_api_token }
200
76
  ```
201
77
 
202
- ## Additional information
78
+ ***
203
79
 
204
- Looking for the advanced usage examples? Check out [the documentation](https://github.com/wildbit/postmark-gem/blob/master/README.md) for the `postmark` gem. The `postmark-rails` gem is built on top of it, so you can benefit from all its features.
80
+ **Note**: The `postmark_settings` hash can contain [any options](https://github.com/wildbit/postmark-gem#communicating-with-the-api) supported by `Postmark::ApiClient`.
205
81
 
206
- ## Requirements
207
82
 
208
- * `postmark` gem version 1.0 and higher is required.
209
- * You will also need a Postmark account, a server and at least one sender signature set up to use it. To get an account, [sign up](https://postmarkapp.com/sign_up)!
83
+ ### Additional information
210
84
 
85
+ Looking for the advanced usage examples? Check out [the documentation](https://github.com/wildbit/postmark-gem/blob/master/README.md) for the [postmark gem](https://github.com/wildbit/postmark-gem).
86
+ The `postmark-rails` gem is built on top of it, so you can benefit from all it's features.
211
87
 
212
88
  ## Note on Patches/Pull Requests
213
89
 
214
- * Fork the project.
215
- * Make your feature addition or bug fix.
216
- * Add tests for it. This is important so we don’t break it in a future version unintentionally.
217
- * Commit, do not mess with rakefile, version, or history.
218
- * Send a pull request. Bonus points for topic branches.
90
+ See [CONTRIBUTING.md](CONTRIBUTING.md) file for details.
219
91
 
220
92
  ## Authors & Contributors
221
93
 
@@ -228,6 +100,16 @@ Looking for the advanced usage examples? Check out [the documentation](https://g
228
100
  * Nicolás Sanguinetti
229
101
  * Laust Rud Jacobsen (rud)
230
102
 
103
+ ## Issues & Comments
104
+
105
+ Feel free to contact us if you encounter any issues with the library or Postmark API.
106
+ Please leave all comments, bugs, requests and issues on the Issues page.
107
+
108
+ ## License
109
+
110
+ The Postmark Rails gem is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) license.
111
+ Refer to the [LICENSE](https://github.com/wildbit/postmark-rails/blob/master/LICENSE) file for more information.
112
+
231
113
  ## Copyright
232
114
 
233
- Copyright © 2010—2018 Wildbit LLC. See LICENSE for details.
115
+ Copyright © 2021 Wildbit LLC.
@@ -4,7 +4,7 @@ gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
6
  gem 'rake', '< 11.0.0'
7
- gem 'postmark', '~> 1.11.0', :path => ENV['POSTMARK_GEM_PATH']
7
+ gem 'postmark', '~> 1.15', :path => ENV['POSTMARK_GEM_PATH']
8
8
  gem 'actionmailer', '~> 3.0.0'
9
9
  gem 'rack-cache', '~> 1.2.0'
10
10
 
@@ -4,7 +4,7 @@ gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
6
  gem 'rake', '< 11.0.0'
7
- gem 'postmark', '~> 1.11.0', :path => ENV['POSTMARK_GEM_PATH']
7
+ gem 'postmark', '~> 1.15', :path => ENV['POSTMARK_GEM_PATH']
8
8
  gem 'actionmailer', :github => 'rails', :branch => '3-2-stable'
9
9
  gem 'i18n', '~> 0.6.0'
10
10
  gem 'rack-cache', '~> 1.2.0'
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
- gem 'postmark', '~> 1.11.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'postmark', '~> 1.15', path: ENV['POSTMARK_GEM_PATH']
7
7
  gem 'actionmailer', '~> 4.0.0'
8
8
 
9
9
  group :test do
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
- gem 'postmark', '~> 1.11.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'postmark', '~> 1.15', path: ENV['POSTMARK_GEM_PATH']
7
7
  gem 'actionmailer', '~> 4.1.0'
8
8
 
9
9
  group :test do
@@ -3,7 +3,7 @@ source "https://rubygems.org"
3
3
  gemspec :path => '../'
4
4
 
5
5
  gem 'json', '< 2.0.0'
6
- gem 'postmark', '~> 1.11.0', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'postmark', '~> 1.15', path: ENV['POSTMARK_GEM_PATH']
7
7
  gem 'actionmailer', '~> 4.2.0'
8
8
 
9
9
  group :test do
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'postmark', '~> 1.15', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'actionmailer', '~> 5.0.0'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'mime-types', '~> 3.2.2'
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'postmark', '~> 1.15', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'actionmailer', '~> 5.1.0'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'mime-types', '~> 3.2.2'
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'postmark', '~> 1.15', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'actionmailer', '~> 5.2.0'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'mime-types', '~> 3.2.2'
11
+ end
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'postmark', '~> 1.15', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'actionmailer', '~> 6.0.0'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'mime-types', '~> 3.2.2'
11
+ end
@@ -3,10 +3,21 @@ require 'action_mailer'
3
3
  require 'postmark'
4
4
 
5
5
  module PostmarkRails
6
- extend self
6
+ module ActionMailerExtensions
7
+ def metadata
8
+ @_message.metadata
9
+ end
7
10
 
8
- def install
11
+ def metadata=(val)
12
+ @_message.metadata=(val)
13
+ end
14
+ end
15
+
16
+ def self.install
17
+ require 'postmark-rails/preview_interceptor'
18
+ require 'postmark-rails/templated_mailer'
9
19
  ActionMailer::Base.add_delivery_method :postmark, Mail::Postmark
20
+ ActionMailer::Base.send(:include, ActionMailerExtensions)
10
21
  end
11
22
  end
12
23
 
@@ -0,0 +1,10 @@
1
+ module PostmarkRails
2
+ class PreviewInterceptor
3
+ def self.previewing_email(message)
4
+ return unless message.templated?
5
+
6
+ message.delivery_method(::Mail::Postmark, ::ActionMailer::Base.postmark_settings)
7
+ message.prerender
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,68 @@
1
+ require 'active_support/hash_with_indifferent_access'
2
+
3
+ module PostmarkRails
4
+ module TemplatedMailerMixin
5
+ READ_ONLY_HEADERS = %w(body content_type subject).freeze
6
+ BODY_STUB = 'Temporary Postmark Template Body'.freeze
7
+ SUBJECT_STUB = 'Temporary Postmark Template Subject'.freeze
8
+ ALIAS_STUB = proc { action_name }
9
+
10
+ def self.included(mailer)
11
+ mailer.default(
12
+ :body => BODY_STUB,
13
+ :content_type => 'text/plain',
14
+ :subject => SUBJECT_STUB,
15
+ :postmark_template_alias => ALIAS_STUB
16
+ )
17
+ mailer.extend(ClassMethods)
18
+ end
19
+
20
+ def template_model(*args)
21
+ message.template_model(*args)
22
+ end
23
+
24
+ def template_model=(model)
25
+ message.template_model = model
26
+ end
27
+
28
+ def mail(headers = {})
29
+ super(self.class.safe_headers(headers))
30
+ ensure
31
+ message.body = standard_template_body
32
+ message.subject = standard_template_subject
33
+ end
34
+
35
+ private
36
+
37
+ module ClassMethods
38
+ def default(headers = {})
39
+ super(safe_headers(headers))
40
+ end
41
+
42
+ def safe_headers(headers = {})
43
+ headers = ActiveSupport::HashWithIndifferentAccess.new(headers)
44
+ violation = READ_ONLY_HEADERS.find { |h| headers.key?(h) }
45
+ raise ArgumentError, "Overriding '#{violation}' header in a templated mailer is not allowed." if violation
46
+ headers
47
+ end
48
+ end
49
+
50
+ def standard_template_body
51
+ "This message is using a Postmark template.\n\n" \
52
+ "Alias: #{message.template_alias.inspect}\n" \
53
+ "Model:\n#{JSON.pretty_generate(message.template_model || {})}\n\n" \
54
+ 'Use the #prerender method on this object to contact the Postmark API ' \
55
+ "to pre-render the template.\n\n" \
56
+ "Cheers,\n" \
57
+ 'Your friends at Postmark'
58
+ end
59
+
60
+ def standard_template_subject
61
+ "Postmark Template: #{message.template_alias.inspect}"
62
+ end
63
+ end
64
+
65
+ class TemplatedMailer < ::ActionMailer::Base
66
+ include TemplatedMailerMixin
67
+ end
68
+ end
@@ -1,3 +1,3 @@
1
1
  module PostmarkRails
2
- VERSION = '0.16.0'
2
+ VERSION = '0.21.0'
3
3
  end
@@ -10,6 +10,10 @@ Gem::Specification.new do |s|
10
10
  s.homepage = %q{http://postmarkapp.com}
11
11
  s.summary = %q{Postmark adapter for ActionMailer}
12
12
 
13
+ s.metadata = {
14
+ "source_code_uri" => "https://github.com/wildbit/postmark-rails"
15
+ }
16
+
13
17
  s.extra_rdoc_files = [
14
18
  "LICENSE",
15
19
  "README.md"
@@ -17,7 +21,7 @@ Gem::Specification.new do |s|
17
21
  s.rdoc_options = ["--charset=UTF-8"]
18
22
 
19
23
  s.add_dependency('actionmailer', ">= 3.0.0")
20
- s.add_dependency('postmark', "~> 1.11.0")
24
+ s.add_dependency('postmark', '>= 1.21.3', '< 2.0')
21
25
 
22
26
  s.add_development_dependency("rake")
23
27
 
data/postmark.png ADDED
Binary file
@@ -32,6 +32,11 @@ class TestMailer < ActionMailer::Base
32
32
  mail(:subject => "Message with inline image.")
33
33
  end
34
34
 
35
+ def message_with_metadata
36
+ metadata['foo'] = 'bar'
37
+ mail(:subject => 'Message with metadata.')
38
+ end
39
+
35
40
  protected
36
41
 
37
42
  def image_file
@@ -0,0 +1 @@
1
+ This is a message with metadata.
@@ -42,4 +42,12 @@ describe "Delivering messages with postmark-rails" do
42
42
  expect { message.deliver }.to change{message.delivered?}.to(true)
43
43
  end
44
44
 
45
- end
45
+ it 'delivers a message with metadata' do
46
+ message = TestMailer.message_with_metadata
47
+
48
+ request = message.to_postmark_hash
49
+
50
+ expect(request['Metadata']).to eq('foo' => 'bar')
51
+ expect { message.deliver }.to change { message.delivered? }.to true
52
+ end
53
+ end
data/spec/spec_helper.rb CHANGED
@@ -10,3 +10,12 @@ ActionMailer::Base.delivery_method = :postmark
10
10
  ActionMailer::Base.prepend_view_path(File.join(File.dirname(__FILE__), "fixtures", "views"))
11
11
 
12
12
  Dir["#{File.dirname(__FILE__)}/fixtures/models/*.rb"].each { |f| require f }
13
+
14
+ RSpec.configure do |config|
15
+ def make_mailer(base, &block)
16
+ mailer = Class.new(base, &block)
17
+ @mailer_number = 0
18
+ stub_const("Mailer#{@mailer_number += 1}", mailer)
19
+ mailer
20
+ end
21
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PostmarkRails::PreviewInterceptor do
4
+ describe '.previewing_email' do
5
+ subject(:preview) { described_class.previewing_email(message) }
6
+ let(:settings) { { :api_token => 'secret' } }
7
+
8
+ before do
9
+ ActionMailer::Base.postmark_settings = settings
10
+ end
11
+
12
+ context 'when given a templated message' do
13
+ let(:message) do
14
+ Mail::Message.new do
15
+ template_alias 'foo'
16
+ end
17
+ end
18
+
19
+ it 'changes the message' do
20
+ message.freeze
21
+ expect { preview }.to raise_error(StandardError, /can't modify/)
22
+ end
23
+
24
+ it 'changes delivery method to Postmark and prerenders' do
25
+ expect(message).to receive(:prerender).exactly(1)
26
+ expect { preview }.to change { message.delivery_method }.to(Mail::Postmark)
27
+ expect(message.delivery_method.settings).to eq(settings)
28
+ end
29
+ end
30
+
31
+ context 'when given a non-templated message' do
32
+ let(:message) { Mail::Message.new }
33
+
34
+ it 'returns the message "as is"' do
35
+ message.freeze
36
+ expect { preview }.to_not raise_error
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,110 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe PostmarkRails::TemplatedMailer do
4
+ subject(:message) { mailer.test_message }
5
+
6
+ shared_examples_for 'templated message' do |template_alias, model|
7
+ it { is_expected.to be_templated }
8
+ specify { expect(message.template_alias).to eq(template_alias) }
9
+ specify { expect(message.template_model).to eq model }
10
+ specify { expect(message.subject).to eq "Postmark Template: #{template_alias.inspect}" }
11
+ specify { expect(message.body_text).to include(template_alias.inspect) }
12
+ specify { expect(message.body_text).to include(JSON.pretty_generate(model || {})) }
13
+ end
14
+
15
+ context 'when template is not specified' do
16
+ let(:mailer) do
17
+ make_mailer(described_class) do
18
+ def test_message
19
+ mail :from => 'sender@wildbit.com', :to => 'recipient@wildbit.com'
20
+ end
21
+ end
22
+ end
23
+
24
+ it_behaves_like 'templated message', 'test_message'
25
+ end
26
+
27
+ context 'when template is specified' do
28
+ let(:mailer) do
29
+ make_mailer(described_class) do
30
+ def test_message
31
+ mail :from => 'sender@wildbit.com',
32
+ :to => 'recipient@wildbit.com',
33
+ :postmark_template_alias => 'custom_template'
34
+ end
35
+ end
36
+ end
37
+
38
+ it_behaves_like 'templated message', 'custom_template'
39
+ end
40
+
41
+ context 'when template model is specified' do
42
+ let(:mailer) do
43
+ make_mailer(described_class) do
44
+ def test_message
45
+ self.template_model = { :foo => 'bar' }
46
+ mail :from => 'sender@wildbit.com',
47
+ :to => 'recipient@wildbit.com'
48
+ end
49
+ end
50
+ end
51
+
52
+ it_behaves_like 'templated message', 'test_message', :foo => 'bar'
53
+ end
54
+
55
+ describe '.default' do
56
+ it 'protects sensitive default headers from being overwritten' do
57
+ %w(subject body content_type).each do |header|
58
+ expect { described_class.default(header => 'foo') }.
59
+ to raise_error(ArgumentError, "Overriding '#{header}' header in a templated mailer is not allowed.")
60
+ end
61
+ end
62
+ end
63
+
64
+ describe '#mail' do
65
+ context "when overriding subject" do
66
+ let(:mailer) do
67
+ make_mailer(described_class) do
68
+ def test_message
69
+ mail :subject => 'Subject'
70
+ end
71
+ end
72
+ end
73
+
74
+ it 'protects it from being overwritten' do
75
+ expect { mailer.test_message.subject }.
76
+ to raise_error(ArgumentError, "Overriding 'subject' header in a templated mailer is not allowed.")
77
+ end
78
+ end
79
+
80
+ context "when overriding body" do
81
+ let(:mailer) do
82
+ make_mailer(described_class) do
83
+ def test_message
84
+ mail :body => 'body'
85
+ end
86
+ end
87
+ end
88
+
89
+ it 'protects it from being overwritten' do
90
+ expect { mailer.test_message.body }.
91
+ to raise_error(ArgumentError, "Overriding 'body' header in a templated mailer is not allowed.")
92
+ end
93
+ end
94
+
95
+ context "when overriding content_type" do
96
+ let(:mailer) do
97
+ make_mailer(described_class) do
98
+ def test_message
99
+ mail :content_type => 'content_type'
100
+ end
101
+ end
102
+ end
103
+
104
+ it 'protects it from being overwritten' do
105
+ expect { mailer.test_message.content_type }.
106
+ to raise_error(ArgumentError, "Overriding 'content_type' header in a templated mailer is not allowed.")
107
+ end
108
+ end
109
+ end
110
+ end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postmark-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Petyo Ivanov
8
8
  - Ilya Sabanin
9
9
  - Artem Chistyakov
10
- autorequire:
10
+ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2018-03-14 00:00:00.000000000 Z
13
+ date: 2021-03-23 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: actionmailer
@@ -30,16 +30,22 @@ dependencies:
30
30
  name: postmark
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
- - - "~>"
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: 1.21.3
36
+ - - "<"
34
37
  - !ruby/object:Gem::Version
35
- version: 1.11.0
38
+ version: '2.0'
36
39
  type: :runtime
37
40
  prerelease: false
38
41
  version_requirements: !ruby/object:Gem::Requirement
39
42
  requirements:
40
- - - "~>"
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: 1.21.3
46
+ - - "<"
41
47
  - !ruby/object:Gem::Version
42
- version: 1.11.0
48
+ version: '2.0'
43
49
  - !ruby/object:Gem::Dependency
44
50
  name: rake
45
51
  requirement: !ruby/object:Gem::Requirement
@@ -66,7 +72,9 @@ files:
66
72
  - ".document"
67
73
  - ".gitignore"
68
74
  - ".travis.yml"
75
+ - ".travis/setup.sh"
69
76
  - CHANGELOG.rdoc
77
+ - CONTRIBUTING.md
70
78
  - Gemfile
71
79
  - LICENSE
72
80
  - README.md
@@ -76,14 +84,22 @@ files:
76
84
  - gemfiles/Gemfile.actionmailer-4.0.x
77
85
  - gemfiles/Gemfile.actionmailer-4.1.x
78
86
  - gemfiles/Gemfile.actionmailer-4.2.x
87
+ - gemfiles/Gemfile.actionmailer-5.0.x
88
+ - gemfiles/Gemfile.actionmailer-5.1.x
89
+ - gemfiles/Gemfile.actionmailer-5.2.x
90
+ - gemfiles/Gemfile.actionmailer-6.0.x
79
91
  - lib/postmark-rails.rb
92
+ - lib/postmark-rails/preview_interceptor.rb
80
93
  - lib/postmark-rails/railtie.rb
94
+ - lib/postmark-rails/templated_mailer.rb
81
95
  - lib/postmark-rails/version.rb
82
96
  - postmark-rails.gemspec
97
+ - postmark.png
83
98
  - spec/fixtures/empty.gif
84
99
  - spec/fixtures/models/test_mailer.rb
85
100
  - spec/fixtures/views/test_mailer/message_with_attachment.erb
86
101
  - spec/fixtures/views/test_mailer/message_with_inline_image.html.erb
102
+ - spec/fixtures/views/test_mailer/message_with_metadata.text.erb
87
103
  - spec/fixtures/views/test_mailer/multipart_message.html.erb
88
104
  - spec/fixtures/views/test_mailer/multipart_message.text.erb
89
105
  - spec/fixtures/views/test_mailer/simple_message.erb
@@ -91,13 +107,16 @@ files:
91
107
  - spec/fixtures/views/test_mailer/tracked_message.html.erb
92
108
  - spec/integration/batch_delivery_spec.rb
93
109
  - spec/integration/delivery_spec.rb
94
- - spec/postmark-rails_spec.rb
95
110
  - spec/spec.opts
96
111
  - spec/spec_helper.rb
112
+ - spec/unit/postmark-rails_spec.rb
113
+ - spec/unit/preview_interceptor_spec.rb
114
+ - spec/unit/templated_mailer_spec.rb
97
115
  homepage: http://postmarkapp.com
98
116
  licenses: []
99
- metadata: {}
100
- post_install_message:
117
+ metadata:
118
+ source_code_uri: https://github.com/wildbit/postmark-rails
119
+ post_install_message:
101
120
  rdoc_options:
102
121
  - "--charset=UTF-8"
103
122
  require_paths:
@@ -113,9 +132,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
132
  - !ruby/object:Gem::Version
114
133
  version: '0'
115
134
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.6.14
118
- signing_key:
135
+ rubygems_version: 3.0.8
136
+ signing_key:
119
137
  specification_version: 4
120
138
  summary: Postmark adapter for ActionMailer
121
139
  test_files:
@@ -123,6 +141,7 @@ test_files:
123
141
  - spec/fixtures/models/test_mailer.rb
124
142
  - spec/fixtures/views/test_mailer/message_with_attachment.erb
125
143
  - spec/fixtures/views/test_mailer/message_with_inline_image.html.erb
144
+ - spec/fixtures/views/test_mailer/message_with_metadata.text.erb
126
145
  - spec/fixtures/views/test_mailer/multipart_message.html.erb
127
146
  - spec/fixtures/views/test_mailer/multipart_message.text.erb
128
147
  - spec/fixtures/views/test_mailer/simple_message.erb
@@ -130,6 +149,8 @@ test_files:
130
149
  - spec/fixtures/views/test_mailer/tracked_message.html.erb
131
150
  - spec/integration/batch_delivery_spec.rb
132
151
  - spec/integration/delivery_spec.rb
133
- - spec/postmark-rails_spec.rb
134
152
  - spec/spec.opts
135
153
  - spec/spec_helper.rb
154
+ - spec/unit/postmark-rails_spec.rb
155
+ - spec/unit/preview_interceptor_spec.rb
156
+ - spec/unit/templated_mailer_spec.rb