smailer 0.7.8 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +4 -0
- data/CHANGELOG.md +202 -0
- data/Gemfile +4 -3
- data/Gemfile.lock +16 -12
- data/README.md +107 -73
- data/generators/smailer/templates/migration.rb.erb +65 -47
- data/lib/generators/smailer/templates/migration.rb.erb +65 -47
- data/lib/smailer/models.rb +3 -2
- data/lib/smailer/models/{mail_campaign_attachment.rb → mail_attachment.rb} +3 -5
- data/lib/smailer/models/mail_campaign.rb +15 -4
- data/lib/smailer/models/mail_template.rb +13 -0
- data/lib/smailer/models/queued_mail.rb +51 -7
- data/lib/smailer/tasks/send.rb +2 -2
- data/lib/smailer/version.rb +2 -2
- data/setup-test-db +14 -0
- data/spec/factories/common.rb +4 -0
- data/spec/factories/models.rb +26 -0
- data/spec/features/issuing_a_newsletter_spec.rb +52 -0
- data/spec/features/sending_oneoff_emails.rb +42 -0
- data/spec/models/mail_campaign_spec.rb +28 -0
- data/spec/models/queued_mail_spec.rb +114 -0
- data/spec/spec_helper.rb +22 -4
- data/upgrading/migrations/smailer_v0_7_3_to_v0_8_0.rb +106 -0
- metadata +13 -6
- data/Guardfile +0 -14
- data/spec/dummy/db/test.sqlite3 +0 -0
- data/spec/models/mail_key_spec.rb +0 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d2e3772412ea4ae474b3e81fdb40a1b283b4c483
|
4
|
+
data.tar.gz: 8c99e9cb73c3c259d97127c0c8f612eb8e779dab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c65340fc1022af2ddcd1b21d71f4246fea5eef4ac4981f13c7a971889cce38709226acff5d293620fd1b328bffc2b35eedfec188ea80bcf661f8731fb9f012b3
|
7
|
+
data.tar.gz: 3790bc6d1bf551eb588cec59da2ae1b00969780e3609550b2b7e9570e8824db185884d4a79412d66b43e74e834eb5b37c042ae0da874bb5761b780eef7f04567
|
data/.gitignore
CHANGED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
## Version v0.8.0
|
2
|
+
|
3
|
+
- Adds support for one-off emails to be send via the same queueing mechanism.
|
4
|
+
- It is now possible to disable the uniqueness validation for a single email
|
5
|
+
per recipient per campaign by passing `:require_uniqueness => false` when
|
6
|
+
creating a `QueuedMail` record.
|
7
|
+
|
8
|
+
**Possible breaking changes:**
|
9
|
+
|
10
|
+
- The `MailCampaignAttachment` chass is now called `MailAttachment`.
|
11
|
+
- The interface to add an attachment has changed.
|
12
|
+
|
13
|
+
Attachments are no longer saved by `add_attachment`. You have to call
|
14
|
+
`Smailer::Models::MailCampaign#save` or `Smailer::Models::MailQueue#save`
|
15
|
+
(if it is one-off email).
|
16
|
+
|
17
|
+
- There have been changes to the database structure.
|
18
|
+
- The message key stored in `QueuedMail#key` is no longer generated based only
|
19
|
+
on predictable input. Now a `SecureRandom`-generated value is alos used.
|
20
|
+
|
21
|
+
**Upgrading from v0.7.3 to v0.8.0**
|
22
|
+
|
23
|
+
To make the required changes in the database, you can use this
|
24
|
+
[smailer_v0_7_3_to_v0_8_0 migration](upgrading/migrations/smailer_v0_7_3_to_v0_8_0.rb).
|
25
|
+
You may need to alter this migration to fit your data.
|
26
|
+
**Don't just run it blindly**.
|
27
|
+
|
28
|
+
## Version v0.7.8 (Feb 11 2015)
|
29
|
+
|
30
|
+
Make sure QueuedMail is deleted
|
31
|
+
|
32
|
+
## Version v0.7.7 (Feb 9 2015)
|
33
|
+
|
34
|
+
Fix Rails 2.x compatibility
|
35
|
+
|
36
|
+
## Version v0.7.5 (Dec 20 2014)
|
37
|
+
|
38
|
+
Fix send task when no mail config is present
|
39
|
+
|
40
|
+
## Version v0.7.4 (Dec 20 2014)
|
41
|
+
|
42
|
+
Fix SMTP support for Rails 2.x
|
43
|
+
|
44
|
+
## Version v0.7.3 (Dec 19 2014)
|
45
|
+
|
46
|
+
Add back accidentally reverted changes
|
47
|
+
|
48
|
+
## Version v0.7.2 (Dec 19 2014)
|
49
|
+
|
50
|
+
Fix mass adding/removing of unsubscribe methods
|
51
|
+
|
52
|
+
## Version v0.7.1 (Dec 1 2014)
|
53
|
+
|
54
|
+
SQL performance improvements
|
55
|
+
|
56
|
+
## Version v0.7.0 (Mar 23 2014)
|
57
|
+
|
58
|
+
Attachments support
|
59
|
+
|
60
|
+
## Version v0.6.3 (Mar 22 2014)
|
61
|
+
|
62
|
+
Rails 4 compatibility
|
63
|
+
|
64
|
+
## Version 0.6.2 (Dec 13, 2012)
|
65
|
+
|
66
|
+
Delivery methods with options now work
|
67
|
+
|
68
|
+
## Version 0.6.1 (Jan 17, 2012)
|
69
|
+
|
70
|
+
Don't use meta_where
|
71
|
+
|
72
|
+
## Version 0.6.0 (Nov 29, 2011)
|
73
|
+
|
74
|
+
Don't keep the body in finished emails
|
75
|
+
|
76
|
+
## Version 0.5.4 (Oct 28, 2011)
|
77
|
+
|
78
|
+
Use mail 2.3+
|
79
|
+
|
80
|
+
## Version 0.5.3 (Oct 27, 2011)
|
81
|
+
|
82
|
+
Fixes a syntax error
|
83
|
+
|
84
|
+
## Version 0.5.2 (Oct 27, 2011)
|
85
|
+
|
86
|
+
Rails 2.3 compatibility for the bounce processor
|
87
|
+
|
88
|
+
## Version 0.5.1 (Oct 27, 2011)
|
89
|
+
|
90
|
+
Fix in the process bounces task
|
91
|
+
|
92
|
+
## Version 0.5.0 (Oct 27, 2011)
|
93
|
+
|
94
|
+
Bounce processing task
|
95
|
+
|
96
|
+
## Version 0.4.4 (Oct 15, 2011)
|
97
|
+
|
98
|
+
Destroy finished mails when a campaign is deleted.
|
99
|
+
|
100
|
+
Addresses a potential issue with marking a finished mail as "opened", when the associated mail campaign has been deleted. Adds MAJOR, MINOR and PATCH version constants.
|
101
|
+
|
102
|
+
## Version 0.4.3 (Oct 6, 2011)
|
103
|
+
|
104
|
+
Fix potential exception in QueuedMail#interpolate
|
105
|
+
|
106
|
+
## Version 0.4.2 (Sep 28, 2011)
|
107
|
+
|
108
|
+
We don't require mail 2.3+ anymore, 2.2+ will do.
|
109
|
+
|
110
|
+
## Version 0.4.1 (Sep 28, 2011)
|
111
|
+
|
112
|
+
Needs mail 2.3+ to avoid ActiveSupport dependency.
|
113
|
+
|
114
|
+
## Version 0.4.0 (Sep 27, 2011)
|
115
|
+
|
116
|
+
Basic VERP-support.
|
117
|
+
|
118
|
+
This version bump is due to improper previous version numbering - when new features were introduced, only the PATCH-level version number was increased.
|
119
|
+
|
120
|
+
## Version 0.3.2 (Sep 27, 2011)
|
121
|
+
|
122
|
+
Runtime requirements fix.
|
123
|
+
|
124
|
+
## Version 0.3.1 (Sep 27, 2011)
|
125
|
+
|
126
|
+
Fix gem dependencies.
|
127
|
+
|
128
|
+
## Version 0.3.0 (Sep 21, 2011)
|
129
|
+
|
130
|
+
Queue locking and basic VERP support.
|
131
|
+
|
132
|
+
## Version 0.2.16 (Sep 16, 2011)
|
133
|
+
|
134
|
+
Rails 2 compatibility mode fixes.
|
135
|
+
|
136
|
+
## Version 0.2.15 (Sep 16, 2011)
|
137
|
+
|
138
|
+
Fix syntax error in Tasks::Send.
|
139
|
+
|
140
|
+
## Version 0.2.14 (Sep 16, 2011)
|
141
|
+
|
142
|
+
More on Rails 2 compatibility in Tasks::Send.
|
143
|
+
|
144
|
+
## Version 0.2.13 (Sep 16, 2011)
|
145
|
+
|
146
|
+
Rails 2 compatibility in Tasks::Send.
|
147
|
+
|
148
|
+
## Version 0.2.12 (Sep 16, 2011)
|
149
|
+
|
150
|
+
Length validation fixes in QueuedMail and FinishedMail.
|
151
|
+
|
152
|
+
## Version 0.2.11 (Sep 13, 2011)
|
153
|
+
|
154
|
+
Settings' defaults.
|
155
|
+
|
156
|
+
## Version 0.2.10 (Sep 13, 2011)
|
157
|
+
|
158
|
+
Fix generated migration in Rails 2 projects.
|
159
|
+
|
160
|
+
## Version 2.8.9 (Sep 13, 2011)
|
161
|
+
|
162
|
+
duplicate the migration template file for Rails 2 compatibility.
|
163
|
+
|
164
|
+
## Version 0.2.8 (Sep 13, 2011)
|
165
|
+
|
166
|
+
Rails 2 migration generator template paths fix.
|
167
|
+
|
168
|
+
## Version 0.2.7 (Sep 13, 2011)
|
169
|
+
|
170
|
+
Rails 2 migration generator fix + USAGE file. (Remove desc method from the definition of the generator, as Rails 2 does not provide such a method.)
|
171
|
+
|
172
|
+
## Version 0.2.6 (Sep 13, 2011)
|
173
|
+
|
174
|
+
Fix typo in Rails 2 migration generator and update the readme.
|
175
|
+
|
176
|
+
## Version 0.2.5 (Sep 13, 2011)
|
177
|
+
|
178
|
+
Fix mistyped Rails 2 generator filename.
|
179
|
+
|
180
|
+
## Version 0.2.4 (Sep 13, 2011)
|
181
|
+
|
182
|
+
Attempt to fix Rails 2 migration generator.
|
183
|
+
|
184
|
+
## Version 0.2.3 (Sep 13, 2011)
|
185
|
+
|
186
|
+
Working Rails 3 migration generator.
|
187
|
+
|
188
|
+
## Version 0.2.2 (Sep 13, 2011)
|
189
|
+
|
190
|
+
Working generator for Rails 2 and 3.
|
191
|
+
|
192
|
+
## Version 0.2.1 (Sep 13, 2011)
|
193
|
+
|
194
|
+
Migration generator.
|
195
|
+
|
196
|
+
## Version 0.2.0 (Sep 2, 2011)
|
197
|
+
|
198
|
+
Hit counting in MailCampaign and delivery reports for FinishedMail.
|
199
|
+
|
200
|
+
## Version bump to 0.1.0 (Sep 2, 2011)
|
201
|
+
|
202
|
+
Initial release.
|
data/Gemfile
CHANGED
@@ -5,14 +5,13 @@ gemspec
|
|
5
5
|
|
6
6
|
gem "rails", ">= 3.0.0"
|
7
7
|
|
8
|
-
group :development do
|
8
|
+
group :development, :test do
|
9
9
|
gem 'sqlite3'
|
10
10
|
|
11
11
|
gem 'guard'
|
12
12
|
gem 'guard-bundler'
|
13
|
-
gem 'guard-spork'
|
14
|
-
gem 'guard-rails'
|
15
13
|
gem 'guard-rspec'
|
14
|
+
gem 'guard-rails'
|
16
15
|
end
|
17
16
|
|
18
17
|
group :test do
|
@@ -21,6 +20,8 @@ group :test do
|
|
21
20
|
gem 'rspec'
|
22
21
|
gem 'rspec-rails'
|
23
22
|
|
23
|
+
gem 'factory_girl'
|
24
|
+
|
24
25
|
gem 'shoulda-matchers'
|
25
26
|
gem 'database_cleaner'
|
26
27
|
end
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
smailer (0.7.
|
4
|
+
smailer (0.7.8)
|
5
5
|
bounce_email (~> 0.2)
|
6
6
|
mail (~> 2.3)
|
7
7
|
|
@@ -44,26 +44,29 @@ GEM
|
|
44
44
|
thread_safe (~> 0.3, >= 0.3.4)
|
45
45
|
tzinfo (~> 1.1)
|
46
46
|
arel (6.0.0)
|
47
|
-
bounce_email (0.2.
|
47
|
+
bounce_email (0.2.6)
|
48
48
|
mail
|
49
49
|
builder (3.2.2)
|
50
50
|
celluloid (0.16.0)
|
51
51
|
timers (~> 4.0.0)
|
52
|
-
childprocess (0.5.5)
|
53
|
-
ffi (~> 1.0, >= 1.0.11)
|
54
52
|
coderay (1.1.0)
|
55
53
|
database_cleaner (1.3.0)
|
56
54
|
diff-lcs (1.2.5)
|
57
55
|
erubis (2.7.0)
|
58
|
-
|
56
|
+
factory_girl (4.5.0)
|
57
|
+
activesupport (>= 3.0.0)
|
58
|
+
ffi (1.9.8)
|
59
59
|
formatador (0.2.5)
|
60
60
|
globalid (0.3.0)
|
61
61
|
activesupport (>= 4.1.0)
|
62
|
-
guard (2.
|
62
|
+
guard (2.12.6)
|
63
63
|
formatador (>= 0.2.4)
|
64
64
|
listen (~> 2.7)
|
65
65
|
lumberjack (~> 1.0)
|
66
|
+
nenv (~> 0.1)
|
67
|
+
notiffany (~> 0.0)
|
66
68
|
pry (>= 0.9.12)
|
69
|
+
shellany (~> 0.0)
|
67
70
|
thor (>= 0.18.1)
|
68
71
|
guard-bundler (2.0.0)
|
69
72
|
bundler (~> 1.0)
|
@@ -75,10 +78,6 @@ GEM
|
|
75
78
|
guard (~> 2.1)
|
76
79
|
guard-compat (~> 1.1)
|
77
80
|
rspec (>= 2.99.0, < 4.0)
|
78
|
-
guard-spork (1.5.1)
|
79
|
-
childprocess (>= 0.2.3)
|
80
|
-
guard (>= 1.1)
|
81
|
-
spork (>= 0.8.4)
|
82
81
|
hike (1.2.3)
|
83
82
|
hitimes (1.2.2)
|
84
83
|
i18n (0.7.0)
|
@@ -97,8 +96,12 @@ GEM
|
|
97
96
|
mini_portile (0.6.2)
|
98
97
|
minitest (5.5.1)
|
99
98
|
multi_json (1.10.1)
|
99
|
+
nenv (0.2.0)
|
100
100
|
nokogiri (1.6.6.2)
|
101
101
|
mini_portile (~> 0.6.0)
|
102
|
+
notiffany (0.0.6)
|
103
|
+
nenv (~> 0.1)
|
104
|
+
shellany (~> 0.0)
|
102
105
|
pry (0.10.1)
|
103
106
|
coderay (~> 1.1.0)
|
104
107
|
method_source (~> 0.8.1)
|
@@ -131,7 +134,7 @@ GEM
|
|
131
134
|
rake (>= 0.8.7)
|
132
135
|
thor (>= 0.18.1, < 2.0)
|
133
136
|
rake (10.4.2)
|
134
|
-
rb-fsevent (0.9.
|
137
|
+
rb-fsevent (0.9.5)
|
135
138
|
rb-inotify (0.9.5)
|
136
139
|
ffi (>= 0.5.0)
|
137
140
|
rspec (3.1.0)
|
@@ -154,6 +157,7 @@ GEM
|
|
154
157
|
rspec-mocks (~> 3.1.0)
|
155
158
|
rspec-support (~> 3.1.0)
|
156
159
|
rspec-support (3.1.2)
|
160
|
+
shellany (0.0.1)
|
157
161
|
shoulda-matchers (2.7.0)
|
158
162
|
activesupport (>= 3.0.0)
|
159
163
|
slop (3.6.0)
|
@@ -182,11 +186,11 @@ PLATFORMS
|
|
182
186
|
DEPENDENCIES
|
183
187
|
bundler (>= 1.0.0)
|
184
188
|
database_cleaner
|
189
|
+
factory_girl
|
185
190
|
guard
|
186
191
|
guard-bundler
|
187
192
|
guard-rails
|
188
193
|
guard-rspec
|
189
|
-
guard-spork
|
190
194
|
rails (>= 3.0.0)
|
191
195
|
rspec
|
192
196
|
rspec-rails
|
data/README.md
CHANGED
@@ -4,27 +4,33 @@
|
|
4
4
|
|
5
5
|
This project is a simple mailer for newsletters, which implements simple queue processing, basic campaign management, [VERP support](http://en.wikipedia.org/wiki/Variable_envelope_return_path), bounce processing and auto-unsubscribe of invalid emails and also assists you in implementing unsubscribe links in the email messages.
|
6
6
|
|
7
|
-
It is intended to be used within a Rails project.
|
7
|
+
It is intended to be used within a Rails project.
|
8
|
+
|
9
|
+
### Supported versions of Rails
|
10
|
+
|
11
|
+
It has been tested with Rails 3.0.x, Rails 3.1.0 and Rails 2.3.5.
|
8
12
|
|
9
13
|
Note: for Rails 3.0.x, you will probably need to use Smailer 0.5.x, because of a version incompatibility with the `mail` Gem.
|
10
14
|
|
15
|
+
It should work with Rails 4 as well, but it hasn't been tested extensively there. Testing and PRs for Rails 4 compatibility are welcome. See [this issue](https://github.com/livebg/smailer/issues/16) for more info.
|
16
|
+
|
11
17
|
## Install
|
12
18
|
|
13
19
|
### Install the gem
|
14
20
|
|
15
21
|
For Rails 3 projects, add the following to your `Gemfile`:
|
16
22
|
|
17
|
-
|
23
|
+
gem 'smailer'
|
18
24
|
|
19
25
|
Then run `bundle install`. For Rails 2.x projects which do not use Bundler, add `config.gem 'smailer'` to your `environment.rb` file and then run `rake gems:install` in your project's root. Also, if you use Rails 2.3.5, you may need to explicitly require a newer version of the `mail` gem, because `mail 2.2.x` has a dependency on ActiveSupport 2.3.6. For example, you can add this to your Rails 2.3.5's `environment.rb`:
|
20
26
|
|
21
|
-
|
27
|
+
config.gem 'mail', :version => '~> 2.3' # we need 2.3.x which does not depend on ActiveSupport 2.3.6
|
22
28
|
|
23
29
|
### Generate and run the migration
|
24
30
|
|
25
31
|
To create the tables needed by Smailer to operate, run the `smailer:migration` generator after installing the gem. For Rails 3, you can do this:
|
26
32
|
|
27
|
-
|
33
|
+
rails g smailer:migration && bundle exec rake db:migrate
|
28
34
|
|
29
35
|
For Rails 2.x projects, use `script/generate smailer_migration && rake db:migrate` to generate and run the migration.
|
30
36
|
|
@@ -32,13 +38,17 @@ For Rails 2.x projects, use `script/generate smailer_migration && rake db:migrat
|
|
32
38
|
|
33
39
|
Since the plugin has been designed to be managed via an admin UI, its settings are stored in a simple key-value table, interfaced by the `Smailer::Models::Property` model. Here is some sample data you can use to initialize your settings with:
|
34
40
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
41
|
+
Smailer::Models::Property.create! :name => 'queue.max_retries', :value => '0', :notes => '0 = unlimited.'
|
42
|
+
Smailer::Models::Property.create! :name => 'queue.max_lifetime', :value => '172800', :notes => 'In seconds; 0 = unlimited.'
|
43
|
+
Smailer::Models::Property.create! :name => 'queue.batch_size', :value => '100', :notes => 'Emails to send per run.'
|
44
|
+
Smailer::Models::Property.create! :name => 'finished_mails.preserve_body', :value => 'false', :notes => 'If this one is set to true, it will take more space in the DB. Use with caution and for debugging purposes only.'
|
39
45
|
|
40
46
|
These properties and values are also the defaults.
|
41
47
|
|
48
|
+
## Upgrading
|
49
|
+
|
50
|
+
If you have an older version of the gem and would like to upgrade to a newer one, take a look [at the changelog](CHANGELOG.md).
|
51
|
+
|
42
52
|
## Usage and documentation
|
43
53
|
|
44
54
|
Sending out newsletters consists of a couple of steps:
|
@@ -52,37 +62,56 @@ Sending out newsletters consists of a couple of steps:
|
|
52
62
|
|
53
63
|
Here is an example how you could proceed with creating and issuing a newsletter:
|
54
64
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
65
|
+
# locate the mailing list we'll be sending to
|
66
|
+
list = Smailer::Models::MailingList.first
|
67
|
+
|
68
|
+
# create a corresponding mail campaign
|
69
|
+
campaign_params = {
|
70
|
+
:from => 'noreply@example.org',
|
71
|
+
:subject => 'My First Campaign!',
|
72
|
+
:body_html => '<h1>Hello</h1><p>World</p>',
|
73
|
+
:body_text => 'Hello, world!',
|
74
|
+
:mailing_list_id => list.id,
|
75
|
+
}
|
76
|
+
campaign = Smailer::Models::MailCampaign.new campaign_params
|
77
|
+
campaign.add_unsubscribe_method :all
|
78
|
+
|
79
|
+
# Add attachments
|
80
|
+
campaign.add_attachment 'attachment.pdf', 'url_or_file_path_to_attachment'
|
81
|
+
|
82
|
+
campaign.save!
|
83
|
+
|
84
|
+
# enqueue mails to be sent out
|
85
|
+
subscribers = %w[
|
86
|
+
subscriber@domain.com
|
87
|
+
office@company.com
|
88
|
+
contact@store.com
|
89
|
+
]
|
90
|
+
subscribers.each do |subscriber|
|
91
|
+
campaign.queued_mails.create! :to => subscriber
|
92
|
+
end
|
93
|
+
|
94
|
+
### One-off emails
|
95
|
+
|
96
|
+
You can send one-off emails that each have a different mail template:
|
97
|
+
|
98
|
+
campaign = Smailer::Models::MailCampaign.first
|
99
|
+
|
100
|
+
# The mail template is first copied from the mail campaign and then any
|
101
|
+
# changes you make are stored in the newly created copy.
|
102
|
+
# In this example, the subject and from fields are copied from the campaign.
|
103
|
+
campaign.queued_mails.create! :to => 'subscriber@domain.com', :body_html => 'my custom body', :body_text => 'my custom body'
|
104
|
+
|
105
|
+
# Changing the campaign now won't change anything in the one-off queued mails.
|
106
|
+
|
107
|
+
# Sending two mails to the same person for a single campaign:
|
108
|
+
campaign.queued_mails.create! :to => 'subscriber@domain.com', :body_html => 'second custom body', :body_text => 'second custom body', require_uniqueness => false
|
109
|
+
|
110
|
+
You can change the `from`, `subject`, `body_html`, `body_text` and you can also call `add_attachment`. For more info check [Smailer::Models::QueuedMail](lib/smailer/models/queued_mail.rb).
|
82
111
|
|
83
112
|
### Attachments
|
84
113
|
|
85
|
-
You can have zero or more attachments to any mail campaign. As demonstrated in the example above, you add them to the
|
114
|
+
You can have zero or more attachments to any mail campaign. As demonstrated in the example above, you add them to the campaign using the `MailCampaign#add_attachment(file_name, url_or_path)` method.
|
86
115
|
|
87
116
|
Any attached files will be referenced at the moment of sending and must be reachable and readable by the send task. Currently, `open-uri` is used to fetch the content of the path or URI. The maximum length of the path/URI field is 2048 symbols.
|
88
117
|
|
@@ -101,31 +130,31 @@ In order to help you with implementing it, Smailer provides you with some interp
|
|
101
130
|
|
102
131
|
Here is an example text you could include in the HTML version of your email to show a unsubscribe link (this also demonstrates how interpolation in the email's body works):
|
103
132
|
|
104
|
-
|
105
|
-
|
133
|
+
<p>If you wish to be removed from our mailinglist go here: <a href="http://yourcomain.com/unsubscribe/%{email_key}">http://yourcomain.com/unsubscribe/%{email_key}</a>.</p>
|
134
|
+
<p>You are subscribed to the list with the following email address: %{escaped_email}</p>
|
106
135
|
|
107
136
|
In this case, you will have to add a route in your Rails app to handle URLs like `'/unsubscribe/:email_key'`. For example, it could lead to `UnsubscribeController#unsubscribe`, which you could implement like so:
|
108
137
|
|
109
|
-
|
110
|
-
|
138
|
+
@email = Smailer::Models::MailKey.find_by_key(params[:email_key]).try(:email)
|
139
|
+
raise ActiveRecord::RecordNotFound unless @email
|
111
140
|
|
112
|
-
|
113
|
-
|
141
|
+
# here you have the @email address of the user who wishes to unsubscribe
|
142
|
+
# and can mark it in your system accordingly (or remove it from your lists altogether)
|
114
143
|
|
115
144
|
### Sending mails
|
116
145
|
|
117
146
|
The emails which have already been placed in the send queue, have to be sent out at some point. This can be done for example with a Rake task which is run periodically via a Cron daemon. Here's an example Rake task you could use:
|
118
147
|
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
148
|
+
# lib/tasks/smailer.rake
|
149
|
+
namespace :smailer do
|
150
|
+
desc 'Send out a batch of queued emails.'
|
151
|
+
task :send_batch => :environment do
|
152
|
+
result = Smailer::Tasks::Send.execute :return_path_domain => 'bounces.mydomain.com', :verp => true
|
153
|
+
result.each do |queue_item, status|
|
154
|
+
puts "Sending #{queue_item.to}: #{status}"
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
129
158
|
|
130
159
|
This task can be executed via `RAILS_ENV=production bundle exec rake smailer:send_batch` (provided you are running it on your production servers).
|
131
160
|
|
@@ -141,26 +170,26 @@ This can be done via a simple cron task, which runs daily (or whatever) on your
|
|
141
170
|
|
142
171
|
Suppose you manage your site's newsletter subscriptions via a `Subscription` model, which has two boolean flags -- `subscribed` and `confirmed` and also an `email` field. You could implement a simple Rake task to be run via a cron daemon this way:
|
143
172
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
173
|
+
task :process_bounces => :environment do
|
174
|
+
subscribed_checker = lambda do |recipient|
|
175
|
+
Subscription.confirmed.subscribed.where(:email => recipient).first.present?
|
176
|
+
end
|
177
|
+
|
178
|
+
Smailer::Tasks::ProcessBounces.execute({
|
179
|
+
:server => 'bounces.mydomain.com',
|
180
|
+
:username => 'no-reply@bounces.mydomain.com',
|
181
|
+
:password => 'mailbox-password',
|
182
|
+
:subscribed_checker => subscribed_checker,
|
183
|
+
}) do |unsubscribe_details|
|
184
|
+
subscription = Subscription.confirmed.subscribed.where(:email => unsubscribe_details[:recipient]).first
|
185
|
+
|
186
|
+
if subscription
|
187
|
+
subscription.subscribed = false
|
188
|
+
subscription.unsubscribe_reason = 'Automatic, due to bounces'
|
189
|
+
subscription.save!
|
190
|
+
end
|
191
|
+
end
|
192
|
+
end
|
164
193
|
|
165
194
|
For more info and also if you'd like to adjust the unsubscribe rules, take a look at the `ProcessBounces.execute` method and its options. It's located in `lib/smailer/tasks/process_bounces.rb`. A few extra options are available, such as `:logger` callbacks (which defaults to `puts`), default action for unprocessed bounces, etc.
|
166
195
|
|
@@ -168,10 +197,15 @@ For more info and also if you'd like to adjust the unsubscribe rules, take a loo
|
|
168
197
|
|
169
198
|
* Tests, tests, tests
|
170
199
|
|
200
|
+
## Tests
|
201
|
+
|
202
|
+
./setup-test-db
|
203
|
+
bundle exec rspec
|
204
|
+
|
171
205
|
## Contribution
|
172
206
|
|
173
207
|
Patches are always welcome. In case you find any issues with this code, please use the project's [Issues](http://github.com/mitio/smailer/issues) page on Github to report them. Feel free to contribute! :)
|
174
208
|
|
175
209
|
## License
|
176
210
|
|
177
|
-
Released under the MIT license.
|
211
|
+
Released under the MIT license.
|