mailkick 0.4.0 → 1.0.1

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
  SHA256:
3
- metadata.gz: 8256980737a3ffda9fce00c4117b05566bf89728f39869e3c5f8afd8a0419728
4
- data.tar.gz: dc8887bf9b238bdc3031e7f1b0aa3ba42a36f371494f62583b319b84dab70162
3
+ metadata.gz: e84a6786c23946b6e27a67a14d75c01da5cde231928d19c65edd2b591de9a153
4
+ data.tar.gz: 1a944d065c7bf4c164db038aabe0073b3759e96a232ec22b29e86cf746ffc02f
5
5
  SHA512:
6
- metadata.gz: 670b60804614ab81daba07cbc20fdde047386b6ea704f66ce4934737b9211b16e34683ad469f318683195aa7036d19615ba4a0363352c0979ec6a40b2467f009
7
- data.tar.gz: b5acb8496859d172360fb59ff06a7406831b79837264758eb9f6ba88c47ff3b731404b7a75bf08c59539553ff8ab44901785485e996c69063bdb086973a70977
6
+ metadata.gz: 3ed9f0315dc5c60ed5b2cc524fd13763566b6126bafceb665dbddcdc2a182f4408a370e267fdcc8ab97cbe616684c7ff5ab91b0fe717d39a65deac854cd3b958
7
+ data.tar.gz: 82c2c1d7a1d0077eb60df59a9d672039b17750462a435afdef19125e26f3c122600a2a8f394c06a3119a64c773d4a6ef7a1f61dc5081dca587735eda80c4a9c3
data/CHANGELOG.md CHANGED
@@ -1,16 +1,38 @@
1
- ## 0.4.0
1
+ ## 1.0.1 (2021-06-20)
2
+
3
+ - Fixed error message when process out-opts not configured
4
+
5
+ ## 1.0.0 (2021-06-03)
6
+
7
+ - Switched from opt-outs to subscriptions
8
+ - Dropped support for Ruby < 2.6 and Rails < 5.2
9
+
10
+ ## 0.4.3 (2020-11-01)
11
+
12
+ - Added support for AWS SES
13
+
14
+ ## 0.4.2 (2020-04-06)
15
+
16
+ - Added support for official SendGrid gem
17
+ - Fixed deprecation warning
18
+
19
+ ## 0.4.1 (2019-10-27)
20
+
21
+ - Added Postmark support
22
+
23
+ ## 0.4.0 (2019-07-15)
2
24
 
3
25
  - Fixed error with model methods and `email_key` option
4
26
  - Fixed bug with `opted_out` scope
5
27
  - Dropped support for Action Mailer 4.2
6
28
 
7
- ## 0.3.1
29
+ ## 0.3.1 (2018-04-21)
8
30
 
9
31
  - Fixed `Secret should not be nil` error in Rails 5.2
10
32
  - Gracefully handle missing email
11
33
  - Added `user` option to `mailkick_unsubscribe_url`
12
34
 
13
- ## 0.3.0
35
+ ## 0.3.0 (2018-04-20)
14
36
 
15
37
  - Improved performance
16
38
  - Fixed `Subscription not found` for Rails 5.2
@@ -18,68 +40,68 @@
18
40
  - Use `smtp_settings[:domain]` for Mailgun
19
41
  - Dropped support for Action Mailer < 4.2
20
42
 
21
- ## 0.2.1
43
+ ## 0.2.1 (2017-10-30)
22
44
 
23
45
  - Fixed errors with Rails 5+
24
46
  - Fixed errors with the latest version of Gibbon
25
47
 
26
- ## 0.2.0
48
+ ## 0.2.0 (2017-05-01)
27
49
 
28
50
  - Added support for Rails 5.1
29
51
 
30
- ## 0.1.6
52
+ ## 0.1.6 (2017-01-10)
31
53
 
32
54
  - Fixed error with frozen strings
33
55
 
34
- ## 0.1.5
56
+ ## 0.1.5 (2016-12-06)
35
57
 
36
58
  - Use `safely`
37
59
  - Only discover services if not manually set
38
60
  - Added `mount` option
39
61
 
40
- ## 0.1.4
62
+ ## 0.1.4 (2016-02-20)
41
63
 
42
64
  - Use `Module#prepend` instead of `alias_method_chain`
43
65
 
44
- ## 0.1.3
66
+ ## 0.1.3 (2015-06-29)
45
67
 
46
68
  - Fixed issue with double escaping tokens
47
69
 
48
- ## 0.1.2
70
+ ## 0.1.2 (2015-06-07)
49
71
 
50
72
  - Added support for Mailgun
51
73
 
52
- ## 0.1.1
74
+ ## 0.1.1 (2015-01-31)
53
75
 
54
76
  - Fixed tokens with `+` in them
55
77
 
56
- ## 0.1.0
78
+ ## 0.1.0 (2014-08-31)
57
79
 
58
80
  - Fixed secret token for Rails 4.1
59
81
 
60
- ## 0.0.6
82
+ ## 0.0.6 (2014-05-09)
61
83
 
62
84
  - Rails 3 fix
63
85
 
64
- ## 0.0.5
86
+ ## 0.0.5 (2014-05-05)
65
87
 
66
88
  - Fixed bug with subscriptions page
67
89
 
68
- ## 0.0.4
90
+ ## 0.0.4 (2014-05-05)
69
91
 
70
92
  - Added `email_key` option to `mailkick_user`
71
93
 
72
- ## 0.0.3
94
+ ## 0.0.3 (2014-05-04)
73
95
 
74
96
  - Added support for multiple lists
75
97
  - Changed `mailkick_user` method names - sorry early adopters :(
76
98
 
77
- ## 0.0.2
99
+ ## 0.0.2 (2014-05-04)
78
100
 
79
101
  - Added Mailchimp service
80
102
  - Fixed Mandrill service
81
103
  - Added `uniq` to `subscribed` scope
82
104
 
83
- ## 0.0.1
105
+ ## 0.0.1 (2014-05-04)
84
106
 
85
107
  - First release
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014-2019 Andrew Kane
1
+ Copyright (c) 2014-2021 Andrew Kane
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,14 +1,15 @@
1
1
  # Mailkick
2
2
 
3
- Email subscriptions made easy
3
+ Email subscriptions for Rails
4
4
 
5
5
  - Add one-click unsubscribe links to your emails
6
6
  - Fetch bounces and spam reports from your email service
7
- - Gracefully handles email address changes
7
+
8
+ **Mailkick 1.0 was recently released** - see [how to upgrade](#upgrading)
8
9
 
9
10
  :postbox: Check out [Ahoy Email](https://github.com/ankane/ahoy_email) for analytics
10
11
 
11
- [![Build Status](https://travis-ci.org/ankane/mailkick.svg?branch=master)](https://travis-ci.org/ankane/mailkick)
12
+ [![Build Status](https://github.com/ankane/mailkick/workflows/build/badge.svg?branch=master)](https://github.com/ankane/mailkick/actions)
12
13
 
13
14
  ## Installation
14
15
 
@@ -18,197 +19,249 @@ Add this line to your application’s Gemfile:
18
19
  gem 'mailkick'
19
20
  ```
20
21
 
21
- And run the generator. This creates a model to store opt-outs.
22
+ And run the generator. This creates a table to store subscriptions.
22
23
 
23
24
  ```sh
25
+ bundle install
24
26
  rails generate mailkick:install
25
27
  rails db:migrate
26
28
  ```
27
29
 
28
- ## How It Works
29
-
30
- Add an unsubscribe link to your emails.
30
+ ## Getting Started
31
31
 
32
- #### Text
32
+ Add `has_subscriptions` to your user model:
33
33
 
34
- ```erb
35
- Unsubscribe: <%= mailkick_unsubscribe_url %>
34
+ ```ruby
35
+ class User < ApplicationRecord
36
+ has_subscriptions
37
+ end
36
38
  ```
37
39
 
38
- #### HTML
40
+ Subscribe to a list
39
41
 
40
- ```erb
41
- <%= link_to "Unsubscribe", mailkick_unsubscribe_url %>
42
+ ```ruby
43
+ user.subscribe("sales")
42
44
  ```
43
45
 
44
- When a user unsubscribes, he or she is taken to a mobile-friendly page and given the option to resubscribe.
46
+ Unsubscribe from a list
45
47
 
46
- To customize the view, run:
47
-
48
- ```sh
49
- rails generate mailkick:views
48
+ ```ruby
49
+ user.unsubscribe("sales")
50
50
  ```
51
51
 
52
- which copies the view into `app/views/mailkick`.
52
+ Check if subscribed
53
53
 
54
- ## Sending Emails
55
-
56
- Before sending marketing emails, make sure the user has not opted out.
54
+ ```ruby
55
+ user.subscribed?("sales")
56
+ ```
57
57
 
58
- Add the following method to models with email addresses.
58
+ Get subscribers for a list (use this for sending emails)
59
59
 
60
60
  ```ruby
61
- class User < ApplicationRecord
62
- mailkick_user
63
- end
61
+ User.subscribed("sales")
64
62
  ```
65
63
 
66
- Get all users who have opted out
64
+ ## Unsubscribe Links
67
65
 
68
- ```ruby
69
- User.opted_out
66
+ Add an unsubscribe link to your emails. For HTML emails, use:
67
+
68
+ ```erb
69
+ <%= link_to "Unsubscribe", mailkick_unsubscribe_url(@user, "sales") %>
70
70
  ```
71
71
 
72
- And those who have not - send to these people
72
+ For text emails, use:
73
73
 
74
- ```ruby
75
- User.not_opted_out
74
+ ```erb
75
+ Unsubscribe: <%= mailkick_unsubscribe_url(@user, "sales") %>
76
76
  ```
77
77
 
78
- Check one user
78
+ When a user unsubscribes, they are taken to a mobile-friendly page and given the option to resubscribe. To customize the view, run:
79
79
 
80
- ```ruby
81
- user.opted_out?
80
+ ```sh
81
+ rails generate mailkick:views
82
82
  ```
83
83
 
84
+ which copies the view into `app/views/mailkick`.
85
+
84
86
  ## Bounces and Spam Reports
85
87
 
86
- Fetch bounces, spam reports, and unsubscribes from your email service.
88
+ Fetch bounces, spam reports, and unsubscribes from your email service. Create `config/initializers/mailkick.rb` with a method to handle opt outs.
87
89
 
88
90
  ```ruby
89
- Mailkick.fetch_opt_outs
91
+ Mailkick.process_opt_outs_method = lambda do |opt_outs|
92
+ emails = opt_outs.map { |v| v[:email] }
93
+ subscribers = User.includes(:mailkick_subscriptions).where(email: emails).index_by(&:email)
94
+
95
+ opt_outs.each do |opt_out|
96
+ subscriber = subscribers[opt_out[:email]]
97
+ next unless subscriber
98
+
99
+ subscriber.mailkick_subscriptions.each do |subscription|
100
+ subscription.destroy if subscription.created_at < opt_out[:time]
101
+ end
102
+ end
103
+ end
90
104
  ```
91
105
 
92
- #### Sendgrid
93
-
94
- Add the gem
106
+ And run:
95
107
 
96
108
  ```ruby
97
- gem 'sendgrid_toolkit'
109
+ Mailkick.fetch_opt_outs
98
110
  ```
99
111
 
100
- Be sure `ENV["SENDGRID_USERNAME"]` and `ENV["SENDGRID_PASSWORD"]` are set.
112
+ The following services are supported:
101
113
 
102
- #### Mandrill
114
+ - [AWS SES](#aws-ses)
115
+ - [Mailchimp](#mailchimp)
116
+ - [Mailgun](#mailgun)
117
+ - [Mandrill](#mandrill)
118
+ - [Postmark](#postmark)
119
+ - [SendGrid](#sendgrid)
120
+
121
+ Will gladly accept pull requests for others.
122
+
123
+ #### AWS SES
124
+
125
+ Add the gem
103
126
 
104
127
  ```ruby
105
- gem 'mandrill-api'
128
+ gem 'aws-sdk-sesv2'
106
129
  ```
107
130
 
108
- Be sure `ENV["MANDRILL_APIKEY"]` is set.
131
+ And [configure your AWS credentials](https://github.com/aws/aws-sdk-ruby#configuration). Requires `ses:ListSuppressedDestinations` permission.
132
+
133
+ If you started using Amazon SES [before November 25, 2019](https://docs.aws.amazon.com/ses/latest/DeveloperGuide/sending-email-suppression-list.html#sending-email-suppression-list-considerations), you have to manually [enable account-level suppression list feature](https://docs.aws.amazon.com/ses/latest/APIReference-V2/API_PutAccountSuppressionAttributes.html).
109
134
 
110
135
  #### Mailchimp
111
136
 
137
+ Add the gem
138
+
112
139
  ```ruby
113
140
  gem 'gibbon', '>= 2'
114
141
  ```
115
142
 
116
- Be sure `ENV["MAILCHIMP_API_KEY"]` and `ENV["MAILCHIMP_LIST_ID"]` are set.
143
+ And set `ENV["MAILCHIMP_API_KEY"]` and `ENV["MAILCHIMP_LIST_ID"]`.
117
144
 
118
145
  #### Mailgun
119
146
 
147
+ Add the gem
148
+
120
149
  ```ruby
121
150
  gem 'mailgun-ruby'
122
151
  ```
123
152
 
124
- Be sure `ENV["MAILGUN_API_KEY"]` is set.
153
+ And set `ENV["MAILGUN_API_KEY"]`.
125
154
 
126
- #### Other
127
-
128
- Will gladly accept pull requests.
129
-
130
- ### Advanced
155
+ #### Mandrill
131
156
 
132
- For more control over services, set them by hand.
157
+ Add the gem
133
158
 
134
159
  ```ruby
135
- Mailkick.services = [
136
- Mailkick::Service::Sendgrid.new(api_key: "API_KEY"),
137
- Mailkick::Service::Mandrill.new(api_key: "API_KEY")
138
- ]
160
+ gem 'mandrill-api'
139
161
  ```
140
162
 
141
- ## Multiple Lists
163
+ And set `ENV["MANDRILL_APIKEY"]`.
164
+
165
+ #### Postmark
142
166
 
143
- You may want to split your emails into multiple categories, like sale emails and order reminders. Set the list in the url:
167
+ Add the gem
144
168
 
145
169
  ```ruby
146
- mailkick_unsubscribe_url(list: "order_reminders")
170
+ gem 'postmark'
147
171
  ```
148
172
 
149
- Pass the `list` option to methods.
173
+ And set `ENV["POSTMARK_API_KEY"]`.
174
+
175
+ #### SendGrid
176
+
177
+ Add the gem
150
178
 
151
179
  ```ruby
152
- User.opted_out(list: "order_reminders")
153
- User.not_opted_out(list: "order_reminders")
154
- user.opted_out?(list: "order_reminders")
180
+ gem 'sendgrid-ruby'
155
181
  ```
156
182
 
157
- ### Opt-In Lists
183
+ And set `ENV["SENDGRID_API_KEY"]`. The API key requires only the `Suppressions` permission.
158
184
 
159
- For opt-in lists, you’ll need to manage the subscribers yourself.
185
+ ### Advanced
160
186
 
161
- Check opt-ins against the opt-outs
187
+ For more control over services, set them by hand.
162
188
 
163
189
  ```ruby
164
- User.where(send_me_sales: true).not_opted_out(list: "sales")
190
+ Mailkick.services = [
191
+ Mailkick::Service::SendGridV2.new(api_key: "API_KEY"),
192
+ Mailkick::Service::Mailchimp.new(api_key: "API_KEY", list_id: "LIST_ID")
193
+ ]
165
194
  ```
166
195
 
167
- Check one user
196
+ ## Reference
197
+
198
+ Access the subscription model directly
168
199
 
169
200
  ```ruby
170
- user.send_me_sales && !user.opted_out?(list: "sales")
201
+ Mailkick::Subscription.all
171
202
  ```
172
203
 
173
- ## Bonus
204
+ ## Upgrading
174
205
 
175
- More great gems for email
206
+ ### 1.0
176
207
 
177
- - [Roadie](https://github.com/Mange/roadie) - inline CSS
178
- - [Letter Opener](https://github.com/ryanb/letter_opener) - preview email in development
208
+ Mailkick 1.0 stores subscriptions instead of opt-outs. To migrate:
179
209
 
180
- ## Reference
181
-
182
- Change how the user is determined
210
+ 1. Add a table to store subscriptions
183
211
 
184
- ```ruby
185
- Mailkick.user_method = ->(email) { User.find_by(email: email) }
212
+ ```sh
213
+ rails generate mailkick:install
214
+ rails db:migrate
186
215
  ```
187
216
 
188
- Use a different email field
217
+ 2. Change the following methods in your code:
189
218
 
190
- ```ruby
191
- mailkick_user email_key: :email_address
192
- ```
219
+ - `mailkick_user` to `has_subscriptions`
220
+ - `User.not_opted_out` to `User.subscribed(list)`
221
+ - `opt_in` to `subscribe(list)`
222
+ - `opt_out` to `unsubscribe(list)`
193
223
 
194
- Unsubscribe
224
+ 3. Add a user and list to `mailkick_unsubscribe_url`
195
225
 
196
226
  ```ruby
197
- user.opt_out
227
+ mailkick_unsubscribe_url(user, list)
198
228
  ```
199
229
 
200
- Resubscribe
230
+ 4. Migrate data for each of your lists
201
231
 
202
232
  ```ruby
203
- user.opt_in
233
+ opted_out_emails = Mailkick::Legacy.opted_out_emails(list: nil)
234
+ opted_out_users = Mailkick::Legacy.opted_out_users(list: nil)
235
+
236
+ User.find_in_batches do |users|
237
+ users.reject! { |u| opted_out_emails.include?(u.email) }
238
+ users.reject! { |u| opted_out_users.include?(u) }
239
+
240
+ now = Time.now
241
+ records =
242
+ users.map do |user|
243
+ {
244
+ subscriber_type: user.class.name,
245
+ subscriber_id: user.id,
246
+ list: "sales",
247
+ created_at: now,
248
+ updated_at: now
249
+ }
250
+ end
251
+
252
+ # use create! for Active Record < 6
253
+ Mailkick::Subscription.insert_all!(records)
254
+ end
204
255
  ```
205
256
 
206
- Access the opt-out model directly
257
+ 5. Drop the `mailkick_opt_outs` table
207
258
 
208
259
  ```ruby
209
- Mailkick::OptOut.all
260
+ drop_table :mailkick_opt_outs
210
261
  ```
211
262
 
263
+ Also, if you use `Mailkick.fetch_opt_outs`, [add a method](#bounces-and-spam-reports) to handle opt outs.
264
+
212
265
  ## History
213
266
 
214
267
  View the [changelog](https://github.com/ankane/mailkick/blob/master/CHANGELOG.md)
@@ -221,3 +274,12 @@ Everyone is encouraged to help improve this project. Here are a few ways you can
221
274
  - Fix bugs and [submit pull requests](https://github.com/ankane/mailkick/pulls)
222
275
  - Write, clarify, or fix documentation
223
276
  - Suggest or add new features
277
+
278
+ To get started with development and testing:
279
+
280
+ ```sh
281
+ git clone https://github.com/ankane/mailkick.git
282
+ cd mailkick
283
+ bundle install
284
+ bundle exec rake test
285
+ ```