rzeszotko-ar_mailer 2.1.10 → 2.1.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +40 -115
- data/Rakefile +1 -1
- data/lib/action_mailer/ar_sendmail.rb +2 -2
- metadata +3 -3
data/README.rdoc
CHANGED
@@ -1,137 +1,62 @@
|
|
1
|
-
= ar_mailer
|
1
|
+
= ar_mailer (with priority queue)
|
2
2
|
|
3
|
-
|
3
|
+
Ar_mailer is a gem that implements an email queue for Ruby on Rails in
|
4
|
+
a transparent way. After changing one setting, all of the usual
|
5
|
+
'deliver_xyz' mailer methods will, instead of actually sending out an
|
6
|
+
email, create a new row in the 'emails' table which is used as the
|
7
|
+
queue. A separate daemon checks that table periodically and does the
|
8
|
+
actual delivery. This can greatly speed up the response time of Rails
|
9
|
+
actions that are locked for a long time by the process of sending out
|
10
|
+
large emails.
|
4
11
|
|
5
|
-
|
12
|
+
This project was forked from:
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
Documentation:
|
10
|
-
|
11
|
-
http://seattlerb.org/ar_mailer
|
14
|
+
https://github.com/adzap/ar_mailer
|
12
15
|
|
13
|
-
|
16
|
+
Which was forked from:
|
14
17
|
|
15
|
-
http://
|
18
|
+
http://rubyforge.org/projects/seattlerb
|
16
19
|
|
17
|
-
|
20
|
+
It adds one additional feature to ar_mailer - the ability to
|
21
|
+
prioritize emails, so that for example newsletter sending out doesn't
|
22
|
+
block the sending out of more time-critical email messages.
|
18
23
|
|
19
|
-
|
24
|
+
For general ar_mailer setup instructions see the original sources:
|
20
25
|
|
21
|
-
|
26
|
+
https://github.com/adzap/ar_mailer
|
22
27
|
|
23
|
-
|
24
|
-
send hundreds of messages. ar_mailer allows you to store messages into the
|
25
|
-
database for later delivery by a separate process, ar_sendmail.
|
28
|
+
http://rubyforge.org/projects/seattlerb
|
26
29
|
|
27
|
-
== Installing ar_mailer
|
30
|
+
== Installing ar_mailer
|
28
31
|
|
29
|
-
|
32
|
+
There is a gem you have to install instead of the usual ar_mailer:
|
30
33
|
|
31
34
|
$ sudo gem uninstall ar_mailer
|
35
|
+
$ sudo gem install rzeszotko-ar_mailer
|
32
36
|
|
33
|
-
Then
|
37
|
+
Then in environment.rb you have to do:
|
34
38
|
|
35
|
-
|
39
|
+
config.gem "rzeszotko-ar_mailer"
|
36
40
|
|
37
|
-
|
41
|
+
You may also need to do an additonal require:
|
38
42
|
|
39
|
-
|
40
|
-
|
41
|
-
# or since version 2.1.7 of this gem you can now just do
|
42
|
-
|
43
|
-
config.gem "adzap-ar_mailer"
|
44
|
-
|
45
|
-
For Rails 2.0, in an initializer file:
|
46
|
-
|
47
|
-
require 'action_mailer/ar_mailer'
|
43
|
+
require 'rzeszotko-ar_mailer'
|
48
44
|
|
49
45
|
== Usage
|
50
46
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
./script/generate ar_mailer
|
64
|
-
|
65
|
-
Or specify a custom model name
|
66
|
-
|
67
|
-
./script/generate ar_mailer Newsletter
|
68
|
-
|
69
|
-
See Alternate Mail Storage if you use a custom model name
|
70
|
-
|
71
|
-
In your mailer class methods you must be sure to set the From address for your emails.
|
72
|
-
Something like:
|
73
|
-
|
74
|
-
def list_send(recipient)
|
75
|
-
from 'no_reply@example.com'
|
76
|
-
# ...
|
77
|
-
|
78
|
-
Edit config/environments/production.rb and set the delivery method:
|
79
|
-
|
80
|
-
config.action_mailer.delivery_method = :activerecord
|
81
|
-
|
82
|
-
Or if you need to, you can set each mailer class delivery method individually:
|
83
|
-
|
84
|
-
class MyMailer < ActionMailer::Base
|
85
|
-
self.delivery_method = :activerecord
|
47
|
+
The difference from regular ar_mailer is in that you can specify a
|
48
|
+
priority for a given email:
|
49
|
+
|
50
|
+
class Emails < ActionMailer::Base
|
51
|
+
def newsletter(newsletter, users)
|
52
|
+
from "John Doe <john.doe@gmail.com>"
|
53
|
+
recipients users.collect(&:email)
|
54
|
+
sent_on Time.now
|
55
|
+
subject newsletter.subject
|
56
|
+
priority 100
|
57
|
+
body :newsletter => newsletter
|
58
|
+
end
|
86
59
|
end
|
87
60
|
|
88
|
-
|
89
|
-
|
90
|
-
database might be causing the exception being raised. In this instance you could
|
91
|
-
override ExceptionNofitier delivery method to be smtp or set the other
|
92
|
-
mailer classes to use ARMailer explicitly.
|
93
|
-
|
94
|
-
Then to run it:
|
95
|
-
|
96
|
-
$ ar_sendmail
|
97
|
-
|
98
|
-
You can also run it from cron with -o, or as a daemon with -d.
|
99
|
-
|
100
|
-
See <tt>ar_sendmail -h</tt> for full details.
|
101
|
-
|
102
|
-
=== Alternate Mail Storage
|
103
|
-
|
104
|
-
By default ar_mailer assumes you are using an ActiveRecord model called
|
105
|
-
Email to store the emails created before sending. If you want to change
|
106
|
-
this you alter it in an intializer like so:
|
107
|
-
|
108
|
-
ActionMailer::Base.email_class = Newsletter
|
109
|
-
|
110
|
-
=== A Word on TLS
|
111
|
-
|
112
|
-
If you are using Ruby >= 1.8.7, TLS will be enabled automatically if your
|
113
|
-
SMTP server supports it. If you do not want it to automatically enabled then
|
114
|
-
set the :tls option to false in your smtp_settings.
|
115
|
-
|
116
|
-
If you are on Ruby <= 1.8.6, then the TLS patch included in this plugin will
|
117
|
-
be loaded, so you don't need another TLS plugin to add the capability. This
|
118
|
-
patch allows you to explicit set if the server supports TLS by setting the
|
119
|
-
:tls option to true in your smtp_settings.
|
120
|
-
|
121
|
-
=== Help
|
122
|
-
|
123
|
-
See ar_sendmail -h for options to ar_sendmail.
|
124
|
-
|
125
|
-
NOTE: You may need to delete an smtp_tls.rb file if you have one lying
|
126
|
-
around. ar_mailer supplies it own.
|
127
|
-
|
128
|
-
== Run as a service (init.d/rc.d scripts)
|
129
|
-
|
130
|
-
For Linux both script and demo config files are in share/linux.
|
131
|
-
See ar_sendmail.conf for setting up your config. Copy the ar_sendmail file
|
132
|
-
to /etc/init.d/ and make it executable. Then for Debian based distros run
|
133
|
-
'sudo update-rc.d ar_sendmail defaults' and it should work. Make sure you have
|
134
|
-
the config file /etc/ar_sendmail.conf in place before starting.
|
135
|
-
|
136
|
-
For FreeBSD or NetBSD script is share/bsd/ar_sendmail. This is old and does not
|
137
|
-
support the config file unless someone wants to submit a patch.
|
61
|
+
Emails with lower priority are send out first, and the default
|
62
|
+
priority (when you do not specify one explicitly) is 0.
|
data/Rakefile
CHANGED
@@ -9,7 +9,7 @@ require './lib/action_mailer/ar_sendmail'
|
|
9
9
|
|
10
10
|
ar_mailer_gemspec = Gem::Specification.new do |s|
|
11
11
|
s.name = %q{rzeszotko-ar_mailer}
|
12
|
-
s.version = "2.1.
|
12
|
+
s.version = "2.1.11"
|
13
13
|
|
14
14
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
15
15
|
s.authors = ["Eric Hodel", "Adam Meehan", "Jarosław Rzeszótko"]
|
@@ -98,7 +98,7 @@ class ActionMailer::ARSendmail
|
|
98
98
|
# to learn how to enable ActiveRecord::Timestamp.
|
99
99
|
|
100
100
|
def self.mailq
|
101
|
-
emails = ActionMailer::Base.email_class.find :all, :order => 'priority ASC'
|
101
|
+
emails = ActionMailer::Base.email_class.find :all, :order => 'priority ASC, id ASC'
|
102
102
|
|
103
103
|
if emails.empty? then
|
104
104
|
puts "Mail queue is empty"
|
@@ -425,7 +425,7 @@ class ActionMailer::ARSendmail
|
|
425
425
|
# last 300 seconds.
|
426
426
|
|
427
427
|
def find_emails
|
428
|
-
options = { :conditions => ['last_send_attempt < ?', Time.now.to_i - 300], :order => 'priority ASC' }
|
428
|
+
options = { :conditions => ['last_send_attempt < ?', Time.now.to_i - 300], :order => 'priority ASC, id ASC' }
|
429
429
|
options[:limit] = batch_size unless batch_size.nil?
|
430
430
|
mail = ActionMailer::Base.email_class.find :all, options
|
431
431
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rzeszotko-ar_mailer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 2.1.
|
9
|
+
- 11
|
10
|
+
version: 2.1.11
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Eric Hodel
|