postmark-rails 0.18.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 938744b498ee1426bb86994d63c17bae10d7486a
4
- data.tar.gz: fd2b297c276a09b55edc281032064c4c98d6738e
2
+ SHA256:
3
+ metadata.gz: 55fc9e5b2ba40ddca5350b181cbe294d65fb940210a482a950c8f75b6377ad08
4
+ data.tar.gz: 667285784c91caefd471a6ae3ee426cc7e16edbf8fa66cf2fd0300be8a822a80
5
5
  SHA512:
6
- metadata.gz: 682b017c3514da84c9ae3611d42c72d6daf48e394ac7fa160cab502d03607a656f0214fa43791b230f6a1b73e916df5bd69a4e537483fbc768f788b9fc5f8b61
7
- data.tar.gz: 3f0882c98e6c84ff7737bbcb7586df5952c4bab5ad5dbf7fc92139c394706c991e4360718b5952ed75f706372380c38138b40ec7117b488225ebe3e91f6d6c93
6
+ metadata.gz: 16211bd6fecc03fd43991dbfcaf590dbacba23b9f2bbcffffc175e97ddaeb9923db64df0f9d84ad5b7158ccc85efce47d281590a589232e9644927ebc6bd214d
7
+ data.tar.gz: d32f35b9ecd48856a7d8c0183e06c38e863904d1bd1d11a6e730a44a48c7682882e94acd6074a30b2c1a9b1ce0826ab864d5791b291b566f4c4e279cdaddde01
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ pkg
8
8
  .rvmrc
9
9
  Gemfile.lock
10
10
  gemfiles/*.lock
11
+ **/*.idea
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/.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,78 @@ 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
23
+ - gemfiles/Gemfile.actionmailer-7.0.x
16
24
  matrix:
17
25
  exclude:
18
- - rvm: 1.8.7
19
- gemfile: Gemfile
20
- - rvm: 1.9.3
21
- gemfile: Gemfile
22
26
  - rvm: 2.0.0
23
27
  gemfile: Gemfile
24
- - rvm: 2.1.9
28
+ - rvm: 2.0.0
29
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
30
+ - rvm: 2.0.0
31
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
32
+ - rvm: 2.0.0
33
+ gemfile: gemfiles/Gemfile.actionmailer-5.2.x
34
+ - rvm: 2.0.0
35
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
36
+ - rvm: 2.0.0
37
+ gemfile: gemfiles/Gemfile.actionmailer-7.0.x
38
+
39
+ - rvm: 2.1.10
25
40
  gemfile: Gemfile
26
- - rvm: 1.8.7
41
+ - rvm: 2.1.10
42
+ gemfile: gemfiles/Gemfile.actionmailer-5.0.x
43
+ - rvm: 2.1.10
44
+ gemfile: gemfiles/Gemfile.actionmailer-5.1.x
45
+ - rvm: 2.1.10
46
+ gemfile: gemfiles/Gemfile.actionmailer-5.2.x
47
+ - rvm: 2.1.10
48
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
49
+ - rvm: 2.1.10
50
+ gemfile: gemfiles/Gemfile.actionmailer-7.0.x
51
+
52
+ - rvm: 2.3.8
53
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
54
+ - rvm: 2.3.8
55
+ gemfile: gemfiles/Gemfile.actionmailer-7.0.x
56
+
57
+ - rvm: 2.4.5
58
+ gemfile: gemfiles/Gemfile.actionmailer-6.0.x
59
+ - rvm: 2.4.5
60
+ gemfile: gemfiles/Gemfile.actionmailer-7.0.x
61
+
62
+ - rvm: 2.5.3
63
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
64
+ - rvm: 2.5.3
65
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
66
+ - rvm: 2.5.3
67
+ gemfile: gemfiles/Gemfile.actionmailer-7.0.x
68
+
69
+ - rvm: 2.6.0
70
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
71
+ - rvm: 2.6.0
72
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
73
+ - rvm: 2.6.0
74
+ gemfile: gemfiles/Gemfile.actionmailer-4.0.x
75
+ - rvm: 2.6.0
76
+ gemfile: gemfiles/Gemfile.actionmailer-4.1.x
77
+ - rvm: 2.6.0
78
+ gemfile: gemfiles/Gemfile.actionmailer-4.2.x
79
+ - rvm: 2.6.0
80
+ gemfile: gemfiles/Gemfile.actionmailer-7.0.x
81
+
82
+ - rvm: 2.7.0
83
+ gemfile: gemfiles/Gemfile.actionmailer-3.0.x
84
+ - rvm: 2.7.0
85
+ gemfile: gemfiles/Gemfile.actionmailer-3.2.x
86
+ - rvm: 2.7.0
27
87
  gemfile: gemfiles/Gemfile.actionmailer-4.0.x
28
- - rvm: 1.8.7
88
+ - rvm: 2.7.0
29
89
  gemfile: gemfiles/Gemfile.actionmailer-4.1.x
30
- - rvm: 1.8.7
90
+ - rvm: 2.7.0
31
91
  gemfile: gemfiles/Gemfile.actionmailer-4.2.x
32
92
  before_install:
33
- - gem update --system
34
- - gem install bundler
93
+ - .travis/setup.sh
data/CHANGELOG.rdoc CHANGED
@@ -1,5 +1,27 @@
1
1
  = Changelog
2
2
 
3
+ == 0.22.0
4
+
5
+ * Added support for Rails 7
6
+
7
+ == 0.21.0
8
+
9
+ * Update minimum postmark gem dependency to avoid use of TLS v1
10
+
11
+ == 0.20.0
12
+
13
+ * Update the postmark gem dependency to 1.x
14
+ * Added support for Rails 6
15
+ * Dropped support for Ruby 1.8.7 and 1.9.3
16
+ * Added support for Ruby 2.7
17
+
18
+ == 0.19.0
19
+
20
+ * Update the postmark gem dependency to 1.15.x.
21
+ * Added support for templated mailers.
22
+ * Added source_code_uri to the gemspec.
23
+ * Tested against all stable versions of ActionMailer 3.0-5.2 and Ruby 1.8.7-2.6.0.
24
+
3
25
  == 0.18.0
4
26
 
5
27
  * Update the postmark gem dependency to 1.14.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,240 +1,94 @@
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>
2
4
 
3
- [![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)
4
-
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).
5
+ # Postmark Rails Gem
6
6
 
7
- ## Supported Rails Versions
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)
8
10
 
9
- * Rails 5.0
10
- * Rails 4.x
11
- * Rails 3.x
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.
12
13
 
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.
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).
14
16
 
15
- ## Configuring your Rails application
17
+ ## Usage
16
18
 
17
- Add `postmark-rails` to your Gemfile and run `bundle install`.
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).
18
21
 
19
- ``` ruby
20
- gem 'postmark-rails'
21
- ```
22
+ ## Requirements
22
23
 
23
- Save your Postmark API token to [config/secrets.yml](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml).
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).
24
26
 
25
- ``` yaml
26
- postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
27
- ```
27
+ Also you will need a [postmark gem](https://github.com/wildbit/postmark-gem) version 1.0 and higher is required.
28
28
 
29
- Set Postmark as your preferred mail delivery method via `config/application.rb`:
29
+ ### Supported Rails Versions
30
30
 
31
- ``` ruby
32
- config.action_mailer.delivery_method = :postmark
33
- config.action_mailer.postmark_settings = { :api_token => Rails.application.secrets.postmark_api_token }
34
- ```
35
-
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 7.0
32
+ * Rails 6.0
33
+ * Rails 5.0
34
+ * Rails 4.x
35
+ * Rails 3.x
37
36
 
38
- ## Tracking opens and tagging your deliveries
37
+ For Rails 2.3 please take a look at [version 0.4](https://github.com/wildbit/postmark-rails/tree/v0.4.2).
38
+ It may miss some new features, but receives all required bug fixes and other support if needed.
39
39
 
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).
40
+ ## Installation
41
41
 
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.**
42
+ Add `postmark-rails` to your Gemfile and run `bundle install`.
43
43
 
44
44
  ``` 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
45
+ gem 'postmark-rails'
58
46
  ```
59
47
 
60
- ## Sending attachments
61
-
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
-
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.
65
48
 
66
- The legacy `:postmark_attachments` attribute is *no longer supported* on Rails 3.2.13 and above.
67
-
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
82
- ```
83
49
 
84
- ## Attaching metadata to messages
50
+ ## Rails 6-7
51
+ Save your Postmark Server API Token to [config/credentials.yml.enc](https://guides.rubyonrails.org/security.html#custom-credentials):
85
52
 
86
- Postmark supports [attaching metadata to messages](https://postmarkapp.com/support/article/1125-custom-metadata-faq-1). All metadata field values will be interpreted and returned in webhook payloads as strings.
53
+ run `rails secret`, then run `rails credentials:edit` and add:
87
54
 
88
- ``` ruby
89
- class TestMailer < ActionMailer::Base
90
-
91
- def message_with_metadata
92
- metadata['foo'] = 'bar'
93
- mail(
94
- :subject => 'meta hello',
95
- :to => 'sheldon@bigbangtheory.com',
96
- :from => 'leonard@bigbangtheory.com'
97
- )
98
- end
99
-
100
- end
55
+ ``` yaml
56
+ postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
101
57
  ```
102
-
103
- ## Sending in batches
104
-
105
- While Postmark is focused on transactional email, we understand that developers
106
- with higher volumes or processing time constraints need to send their messages
107
- in batches. To facilitate this we provide a batching endpoint that permits you
108
- to send up to 500 well-formed Postmark messages in a single API call.
58
+ Set Postmark as your preferred mail delivery method via `config/application.rb`:
109
59
 
110
60
  ``` ruby
111
- client = Postmark::ApiClient.new('your-api-token')
112
-
113
- messages = []
114
- messages << DigestMailer.weekly_digest(@user1)
115
- messages << DigestMailer.weekly_digest(@user2)
116
-
117
- client.deliver_messages(messages)
118
-
119
- messages.first.delivered?
120
- # => true
121
-
122
- messages.all?(&:delivered)
123
- # => true
61
+ config.action_mailer.delivery_method = :postmark
62
+ config.action_mailer.postmark_settings = { api_token: Rails.application.credentials.postmark_api_token }
124
63
  ```
125
64
 
126
- ## Error handling
127
-
128
- The gem respects the `ActionMailer::Base.raise_delivery_errors` setting and will surpress any exceptions
129
- if it’s set to `false`. When delivery errors are enabled, the gem can raise any one of the exceptions
130
- listed in the [postmark](https://github.com/wildbit/postmark-gem#error-handling) gem docs.
131
-
132
-
133
- ### ActionMailer 5
134
-
135
- For ActionMailer 5 and above, use `ActionMailer::Base.rescue_from` to define handlers for
136
- each error you care about.
65
+ ## Rails 3-5
66
+ Save your Postmark Server API token to [config/secrets.yml](http://guides.rubyonrails.org/4_1_release_notes.html#config-secrets-yml).
137
67
 
138
- #### Example
139
-
140
- ``` ruby
141
- class ApplicationMailer < ActionMailer::Base
142
- default from: 'user@example.org'
143
- layout 'mailer'
144
-
145
- rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
146
-
147
- private
148
-
149
- def postmark_client
150
- ::Postmark::ApiClient.new(ActionMailer::Base.postmark_settings[:api_token],
151
- ActionMailer::Base.postmark_settings.except(:api_token))
152
- end
153
-
154
-
155
- # This is just an example. Sometimes you might not want to reactivate
156
- # an address that hard bounced.
157
- # Warning: Having too many bounces can affect your delivery reputation
158
- # with email providers
159
- def reactivate_and_retry(error)
160
- Rails.logger.info("Error when sending #{message} to #{error.recipients.join(', ')}")
161
- Rails.logger.info(error)
162
-
163
- error.recipients.each do |recipient|
164
- bounce = postmark_client.bounces(emailFilter: recipient).first
165
- next unless bounce
166
- postmark_client.activate_bounce(bounce[:id])
167
- end
168
-
169
- # Try again immediately
170
- message.deliver
171
- end
172
- end
68
+ ``` yaml
69
+ postmark_api_token: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
173
70
  ```
174
71
 
175
- ### ActionMailer 4 and below
176
-
177
- Wrap any calls to `#deliver_now` in error handlers like the one described
178
- in the [postmark](https://github.com/wildbit/postmark-gem#error-handling) gem
179
- docs.
180
-
181
- Rails 4.2 introduces `#deliver_later` but doesn’t support `rescue_from` for
182
- mailer classes. Instead, use the following monkey patch for
183
- `ActionMailer::DeliveryJob`.
72
+ Set Postmark as your preferred mail delivery method via `config/application.rb`:
184
73
 
185
74
  ``` ruby
186
- # app/mailers/application_mailer.rb
187
-
188
- class ApplicationMailer < ActionMailer::Base
189
- default from: 'user@example.org'
190
- end
191
-
192
- class ActionMailer::DeliveryJob
193
- rescue_from Postmark::InactiveRecipientError, with: :reactivate_and_retry
194
-
195
- def postmark_client
196
- ::Postmark::ApiClient.new(ActionMailer::Base.postmark_settings[:api_token],
197
- ActionMailer::Base.postmark_settings.except(:api_token))
198
- end
199
-
200
-
201
- # This is just an example. Sometimes you might not want to reactivate
202
- # an address that hard bounced.
203
- # Warning: Having too many bounces can affect your delivery reputation
204
- # with email providers
205
- def reactivate_and_retry(error)
206
- Rails.logger.info("Error when sending a message to #{error.recipients.join(', ')}")
207
- Rails.logger.info(error)
208
-
209
- error.recipients.each do |recipient|
210
- bounce = postmark_client.bounces(emailFilter: recipient).first
211
- next unless bounce
212
- postmark_client.activate_bounce(bounce[:id])
213
- end
214
-
215
- # Try again immediately
216
- perform(*arguments)
217
- end
218
- end
75
+ config.action_mailer.delivery_method = :postmark
76
+ config.action_mailer.postmark_settings = { :api_token => Rails.application.secrets.postmark_api_token }
219
77
  ```
220
78
 
221
- ## Additional information
79
+ ***
222
80
 
223
- 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.
81
+ **Note**: The `postmark_settings` hash can contain [any options](https://github.com/wildbit/postmark-gem#communicating-with-the-api) supported by `Postmark::ApiClient`.
224
82
 
225
- ## Requirements
226
83
 
227
- * `postmark` gem version 1.0 and higher is required.
228
- * 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)!
84
+ ### Additional information
229
85
 
86
+ 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).
87
+ The `postmark-rails` gem is built on top of it, so you can benefit from all it's features.
230
88
 
231
89
  ## Note on Patches/Pull Requests
232
90
 
233
- * Fork the project.
234
- * Make your feature addition or bug fix.
235
- * Add tests for it. This is important so we don’t break it in a future version unintentionally.
236
- * Commit, do not mess with rakefile, version, or history.
237
- * Send a pull request. Bonus points for topic branches.
91
+ See [CONTRIBUTING.md](CONTRIBUTING.md) file for details.
238
92
 
239
93
  ## Authors & Contributors
240
94
 
@@ -247,6 +101,16 @@ Looking for the advanced usage examples? Check out [the documentation](https://g
247
101
  * Nicolás Sanguinetti
248
102
  * Laust Rud Jacobsen (rud)
249
103
 
104
+ ## Issues & Comments
105
+
106
+ Feel free to contact us if you encounter any issues with the library or Postmark API.
107
+ Please leave all comments, bugs, requests and issues on the Issues page.
108
+
109
+ ## License
110
+
111
+ The Postmark Rails gem is licensed under the [MIT](http://www.opensource.org/licenses/mit-license.php) license.
112
+ Refer to the [LICENSE](https://github.com/wildbit/postmark-rails/blob/master/LICENSE) file for more information.
113
+
250
114
  ## Copyright
251
115
 
252
- Copyright © 2010—2018 Wildbit LLC. See LICENSE for details.
116
+ 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.14.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.14.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.14.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.14.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.14.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
@@ -0,0 +1,11 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path => '../'
4
+
5
+ gem 'postmark', '~> 1.22', path: ENV['POSTMARK_GEM_PATH']
6
+ gem 'actionmailer', '~> 7.0.0'
7
+
8
+ group :test do
9
+ gem 'rspec', '~> 3.7'
10
+ gem 'mime-types', '~> 3.2.2'
11
+ end
@@ -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.18.0'
2
+ VERSION = '0.22.0'
3
3
  end
@@ -14,6 +14,8 @@ module PostmarkRails
14
14
  end
15
15
 
16
16
  def self.install
17
+ require 'postmark-rails/preview_interceptor'
18
+ require 'postmark-rails/templated_mailer'
17
19
  ActionMailer::Base.add_delivery_method :postmark, Mail::Postmark
18
20
  ActionMailer::Base.send(:include, ActionMailerExtensions)
19
21
  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.14.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
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.18.0
4
+ version: 0.22.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-08-22 00:00:00.000000000 Z
13
+ date: 2022-01-25 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.14.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.14.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,10 +84,18 @@ 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
91
+ - gemfiles/Gemfile.actionmailer-7.0.x
79
92
  - lib/postmark-rails.rb
93
+ - lib/postmark-rails/preview_interceptor.rb
80
94
  - lib/postmark-rails/railtie.rb
95
+ - lib/postmark-rails/templated_mailer.rb
81
96
  - lib/postmark-rails/version.rb
82
97
  - postmark-rails.gemspec
98
+ - postmark.png
83
99
  - spec/fixtures/empty.gif
84
100
  - spec/fixtures/models/test_mailer.rb
85
101
  - spec/fixtures/views/test_mailer/message_with_attachment.erb
@@ -92,13 +108,16 @@ files:
92
108
  - spec/fixtures/views/test_mailer/tracked_message.html.erb
93
109
  - spec/integration/batch_delivery_spec.rb
94
110
  - spec/integration/delivery_spec.rb
95
- - spec/postmark-rails_spec.rb
96
111
  - spec/spec.opts
97
112
  - spec/spec_helper.rb
113
+ - spec/unit/postmark-rails_spec.rb
114
+ - spec/unit/preview_interceptor_spec.rb
115
+ - spec/unit/templated_mailer_spec.rb
98
116
  homepage: http://postmarkapp.com
99
117
  licenses: []
100
- metadata: {}
101
- post_install_message:
118
+ metadata:
119
+ source_code_uri: https://github.com/wildbit/postmark-rails
120
+ post_install_message:
102
121
  rdoc_options:
103
122
  - "--charset=UTF-8"
104
123
  require_paths:
@@ -114,9 +133,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
133
  - !ruby/object:Gem::Version
115
134
  version: '0'
116
135
  requirements: []
117
- rubyforge_project:
118
- rubygems_version: 2.6.14
119
- signing_key:
136
+ rubygems_version: 3.3.5
137
+ signing_key:
120
138
  specification_version: 4
121
139
  summary: Postmark adapter for ActionMailer
122
140
  test_files:
@@ -132,6 +150,8 @@ test_files:
132
150
  - spec/fixtures/views/test_mailer/tracked_message.html.erb
133
151
  - spec/integration/batch_delivery_spec.rb
134
152
  - spec/integration/delivery_spec.rb
135
- - spec/postmark-rails_spec.rb
136
153
  - spec/spec.opts
137
154
  - spec/spec_helper.rb
155
+ - spec/unit/postmark-rails_spec.rb
156
+ - spec/unit/preview_interceptor_spec.rb
157
+ - spec/unit/templated_mailer_spec.rb