ar_mailer_revised 1.0.0 → 1.0.1
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 +4 -4
- data/README.md +54 -33
- data/lib/ar_mailer_revised/email_scaffold.rb +1 -1
- data/lib/ar_mailer_revised/mailman.rb +4 -0
- data/lib/ar_mailer_revised/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0b1e7179059d80144067968beac5f41151eda097
|
4
|
+
data.tar.gz: 42554e87ed8bfb15baef54d94a7c0e28e0c7b515
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cb4f0f7c22ebf0e85ff61ded487ac20acf38036e0b8f45dd074923f153aeda836e416af01d73fa14263fe9f2203f76e7b8a653d938e8408f2d670899ccd2d2e
|
7
|
+
data.tar.gz: 827bb354ebb58010182591543be6ee60774146de9e5b9f5eda8649f39daf44d6c309c2cd986b3bb7a73e7e9812ce4b133099507b4b6b3613d6b4d0d846f966db
|
data/README.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# ArMailerRevised
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/ar_mailer_revised)
|
3
4
|
[](https://codeclimate.com/github/Stex/ar_mailer_revised)
|
4
|
-
](https://travis-ci.org/Stex/ar_mailer_revised)
|
5
6
|
|
6
|
-
[ArMailer](https://github.com/seattlerb/ar_mailer)
|
7
|
+
[ArMailer](https://github.com/seattlerb/ar_mailer) is a great gem which allows you to store emails in your application's database and batch deliver
|
7
8
|
them later using a background task.
|
8
9
|
|
9
10
|
However, it was not compatible with newer versions of Rails and also lacking some of the functionality I needed in my applications.
|
@@ -57,11 +58,15 @@ add them to the migration before migrating.
|
|
57
58
|
First of all, you have to set ActionMailer to use the gem's delivery method.
|
58
59
|
This can be done per environment or globally for the application using either
|
59
60
|
|
60
|
-
|
61
|
+
```ruby
|
62
|
+
config.action_mailer.delivery_method = :activerecord
|
63
|
+
```
|
61
64
|
|
62
65
|
or - not inside a configuration file
|
63
66
|
|
64
|
-
|
67
|
+
```ruby
|
68
|
+
ActionMailer::Base.delivery_method = :activerecord
|
69
|
+
```
|
65
70
|
|
66
71
|
### SMTP-Settings
|
67
72
|
|
@@ -88,13 +93,15 @@ ArMailerRevised uses the normal ActionMailer::Base templates, so you can write
|
|
88
93
|
deliver-methods like you would for direct email sending.
|
89
94
|
On delivering, the email will be stored in the database and not being sent diretly.
|
90
95
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
96
|
+
```ruby
|
97
|
+
class TestMailer < ActionMailer::Base
|
98
|
+
default from: 'from@example.com'
|
99
|
+
|
100
|
+
def basic_email
|
101
|
+
mail(to: 'basic_email@example.com', subject: 'Basic Email Subject', body: 'Basic Email Body')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
```
|
98
105
|
|
99
106
|
### Setting a custom delivery time
|
100
107
|
|
@@ -103,10 +110,12 @@ the resulting email record. One of them is +ar_mailer_delivery_time+.
|
|
103
110
|
This method sets a time which determines the earliest sending time for this email,
|
104
111
|
in other words: If you set this time, the email won't be sent prior to it.
|
105
112
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
113
|
+
```ruby
|
114
|
+
def delayed_email
|
115
|
+
ar_mailer_delivery_time Time.now + 2.hours
|
116
|
+
mail(to: 'delayed_email@example.com', subject: 'Delayed Email Subject', :body => 'Delayed Email Body')
|
117
|
+
end
|
118
|
+
```
|
110
119
|
|
111
120
|
**Important**: It may happen that the Rails logging output of the generated mail may still contain
|
112
121
|
custom attributes (like the delivery time) in its header. This happens because ActionMailer will
|
@@ -117,19 +126,21 @@ log the email before actually delivering it. The generated email will **not** co
|
|
117
126
|
It is possible to set own SMTP settings for each email in the system which will then be used for delivery.
|
118
127
|
These settings may contain everything the global settings do (see above).
|
119
128
|
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
```ruby
|
130
|
+
def custom_smtp_email
|
131
|
+
ar_mailer_smtp_settings({
|
132
|
+
:address => 'localhost',
|
133
|
+
:port => 25,
|
134
|
+
:domain => 'localhost.localdomain',
|
135
|
+
:user_name => 'some.user',
|
136
|
+
:password => 'some.password',
|
137
|
+
:authentication => :plain,
|
138
|
+
:enable_starttls_auto => true
|
139
|
+
})
|
140
|
+
|
141
|
+
mail(to: 'custom_smtp_email@example.com', subject: 'Custom SMTP Email Subject', :body => 'Custom SMTP Email Body')
|
142
|
+
end
|
143
|
+
```
|
133
144
|
|
134
145
|
**Important**: As the mailer has to use the password to connect to the SMTP server, it is stored in the database in plain text!
|
135
146
|
If this means a security issue to you, please use only the global settings which are loaded from the environment and not stored in the database.
|
@@ -145,10 +156,12 @@ You can add custom attributes to the email table simply by altering the generate
|
|
145
156
|
|
146
157
|
In the email delivering method, these attributes may then be filled with the actual data using the `ar_mailer_attribute` helper method:
|
147
158
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
159
|
+
```ruby
|
160
|
+
def custom_attribute_email
|
161
|
+
ar_mailer_attribute :a_number, 42
|
162
|
+
mail(to: 'custom_attribute_email@example.com', subject: 'Custom Attribute Email Subject', :body => 'Custom Attribute Email Body')
|
163
|
+
end
|
164
|
+
```
|
152
165
|
|
153
166
|
### Sending Emails
|
154
167
|
|
@@ -158,9 +171,17 @@ be accessed from the application's root directory.
|
|
158
171
|
It accepts the argument `-h` (or `--help`), showing all available options.
|
159
172
|
If you call it without options, it will run a single batch sending in the foreground and exist afterwards.
|
160
173
|
|
161
|
-
There will be daemon functionality in the future (mostly to avoid loading the application
|
174
|
+
There will be daemon functionality in the future (mostly to avoid loading the application environment
|
162
175
|
every single time emails are being sent), for now I suggest using a gem like [whenever](https://github.com/javan/whenever)
|
163
176
|
to run the executable every X minutes.
|
177
|
+
|
178
|
+
An entry in whenever's `schedule.rb` might look like this:
|
179
|
+
|
180
|
+
```ruby
|
181
|
+
every 5.minutes do
|
182
|
+
command "cd #{path} && bundle exec ar_sendmail -c #{path} -e production -b 25 --log-file './log/ar_mailer.log' --log-level info"
|
183
|
+
end
|
184
|
+
```
|
164
185
|
|
165
186
|
### SMTP settings for common providers (to be extended)
|
166
187
|
|
@@ -240,6 +240,10 @@ module ArMailerRevised
|
|
240
240
|
end
|
241
241
|
end
|
242
242
|
|
243
|
+
#----------------------------------------------------------------
|
244
|
+
# Email Record Alteration
|
245
|
+
#----------------------------------------------------------------
|
246
|
+
|
243
247
|
#
|
244
248
|
# Adjusts the last send attempt timestamp in the given
|
245
249
|
# email to the current time.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ar_mailer_revised
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stefan Exner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|