zendesk-ar_mailer 1.4.6 → 2.1.5
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.
- data/History.txt +54 -0
- data/README.rdoc +149 -0
- data/Rakefile +13 -19
- data/generators/ar_mailer/ar_mailer_generator.rb +25 -0
- data/generators/ar_mailer/templates/migration.rb +15 -0
- data/generators/ar_mailer/templates/model.rb +2 -0
- data/lib/action_mailer/ar_mailer.rb +9 -89
- data/lib/action_mailer/ar_sendmail.rb +65 -124
- data/lib/ar_sendmail_logger.rb +6 -1
- data/share/linux/ar_sendmail +6 -3
- data/test/{action_mailer.rb → resources/action_mailer.rb} +26 -15
- data/test/test_armailer.rb +6 -13
- data/test/test_arsendmail.rb +71 -191
- data/test/test_helper.rb +9 -0
- metadata +19 -13
- data/Manifest.txt +0 -15
- data/README.txt +0 -80
data/History.txt
CHANGED
@@ -1,3 +1,57 @@
|
|
1
|
+
= 2.1.5
|
2
|
+
|
3
|
+
* Bugs fixed
|
4
|
+
* Load ar_mailer after environment to fix issue with lazy loading of ActionMailer in Rails 2.3
|
5
|
+
|
6
|
+
= 2.1.4
|
7
|
+
|
8
|
+
* Bugs fixed
|
9
|
+
* Explicitly require ar_mailer in ar_sendmail because its not getting loaded by the Rails environment for some reason
|
10
|
+
|
11
|
+
= 2.1.3
|
12
|
+
|
13
|
+
* Tests now pass on gem install
|
14
|
+
* Removed deprecated ActionMailer::ARMailer class
|
15
|
+
* Bugs fixed
|
16
|
+
* Fixed issue with pre-loading ActionMailer. No use ActionMailer::Base.email_class directly rather than store in ARSendmail instance var so no need to pre-load ActionMailer.
|
17
|
+
|
18
|
+
= 2.1.2
|
19
|
+
|
20
|
+
* Bugs fixed
|
21
|
+
* Require ar_mailer in ar_sendmail since the change to remove TableName and use email_class
|
22
|
+
|
23
|
+
= 2.1.1
|
24
|
+
|
25
|
+
* Force gem rebuild
|
26
|
+
|
27
|
+
= 2.1.0
|
28
|
+
|
29
|
+
* Switched to using a Rails generator for migration and model files. The ar_sendmail options have been removed.
|
30
|
+
|
31
|
+
= 2.0.2
|
32
|
+
|
33
|
+
* Removed TableName option from ar_sendmail options as its redundant. The Rails environment gets loaded so the settings for email class also get loaded
|
34
|
+
* Bugs fixed
|
35
|
+
* Email class reloading issue in development mode causing AR email class defaults to be lost when cached
|
36
|
+
|
37
|
+
= 2.0.1
|
38
|
+
|
39
|
+
* Added option to use smtp setting of :tls => false to disable TLS auto start in Ruby 1.8.7+
|
40
|
+
* Removed some cruft which can be handled by ActiveSupport
|
41
|
+
|
42
|
+
= 2.0.0
|
43
|
+
|
44
|
+
* Removed need to use ARMailer subclass. Just set the delivery method and you are ready to go. Backwards compatible with a deprecation notice if you subclass old ARMailer class.
|
45
|
+
* Only include SMTP TLS patch if Ruby version < 1.8.7 as it has an alternative. Changes based on Calvin Yu's [cyu] fork.
|
46
|
+
* Renamed default migration name to the modern Rails default
|
47
|
+
* Only authenticate if emails waiting to be sent
|
48
|
+
* Added --version switch to ar_sendmail binary
|
49
|
+
* Created a lighthouse account for this project (adzap fork only). See README.
|
50
|
+
|
51
|
+
= 1.4.4
|
52
|
+
|
53
|
+
* Exit init.d script with message if no mailers defined.
|
54
|
+
|
1
55
|
= 1.4.3
|
2
56
|
|
3
57
|
* Bugs fixed
|
data/README.rdoc
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
= ar_mailer
|
2
|
+
|
3
|
+
A two-phase delivery agent for ActionMailer
|
4
|
+
|
5
|
+
Rubyforge Project:
|
6
|
+
|
7
|
+
http://rubyforge.org/projects/seattlerb
|
8
|
+
|
9
|
+
Documentation:
|
10
|
+
|
11
|
+
http://seattlerb.org/ar_mailer
|
12
|
+
|
13
|
+
and for forked additions
|
14
|
+
|
15
|
+
http://github.com/adzap/ar_mailer/wikis
|
16
|
+
|
17
|
+
Bugs:
|
18
|
+
|
19
|
+
http://adzap.lighthouseapp.com/projects/26997-ar_mailer
|
20
|
+
|
21
|
+
== About
|
22
|
+
|
23
|
+
Even delivering email to the local machine may take too long when you have to
|
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.
|
26
|
+
|
27
|
+
== Installing ar_mailer (forked)
|
28
|
+
|
29
|
+
Before installing you will need to make sure the original gem is uninstalled as they can't coexist:
|
30
|
+
|
31
|
+
$ sudo gem uninstall ar_mailer
|
32
|
+
|
33
|
+
Install the gem from GitHub gems server:
|
34
|
+
|
35
|
+
First, if you haven't already:
|
36
|
+
|
37
|
+
$ sudo gem sources -a http://gems.github.com
|
38
|
+
|
39
|
+
Then
|
40
|
+
|
41
|
+
$ sudo gem install adzap-ar_mailer
|
42
|
+
|
43
|
+
For Rails >= 2.1, in your environment.rb:
|
44
|
+
|
45
|
+
config.gem "adzap-ar_mailer", :lib => 'action_mailer/ar_mailer', :source => 'http://gems.github.com'
|
46
|
+
|
47
|
+
For Rails 2.0, in an initializer file:
|
48
|
+
|
49
|
+
require 'action_mailer/ar_mailer'
|
50
|
+
|
51
|
+
== Usage
|
52
|
+
|
53
|
+
Go to your Rails project:
|
54
|
+
|
55
|
+
$ cd your_rails_project
|
56
|
+
|
57
|
+
Create the migration and model:
|
58
|
+
|
59
|
+
This shows the options which are only the model name, which defaults to Email
|
60
|
+
|
61
|
+
./script/generate ar_mailer -h
|
62
|
+
|
63
|
+
Then run with defaults
|
64
|
+
|
65
|
+
./script/generate ar_mailer
|
66
|
+
|
67
|
+
Or specify a custom model name
|
68
|
+
|
69
|
+
./script/generate ar_mailer Newsletter
|
70
|
+
|
71
|
+
See Alternate Mail Storage if you use a custom model name
|
72
|
+
|
73
|
+
In your mailer class methods you must be sure to set the From address for your emails.
|
74
|
+
Something like:
|
75
|
+
|
76
|
+
def list_send(recipient)
|
77
|
+
from 'no_reply@example.com'
|
78
|
+
# ...
|
79
|
+
|
80
|
+
Edit config/environments/production.rb and set the delivery method:
|
81
|
+
|
82
|
+
config.action_mailer.delivery_method = :activerecord
|
83
|
+
|
84
|
+
Or if you need to, you can set each mailer class delivery method individually:
|
85
|
+
|
86
|
+
class MyMailer < ActionMailer::Base
|
87
|
+
self.delivery_method = :activerecord
|
88
|
+
end
|
89
|
+
|
90
|
+
This can be useful when using plugins like ExceptionNotification. Where it
|
91
|
+
might be foolish to tie the sending of the email alert to the database when the
|
92
|
+
database might be causing the exception being raised. In this instance you could
|
93
|
+
override ExceptionNofitier delivery method to be smtp or set the other
|
94
|
+
mailer classes to use ARMailer explicitly.
|
95
|
+
|
96
|
+
Then to run it:
|
97
|
+
|
98
|
+
$ ar_sendmail
|
99
|
+
|
100
|
+
You can also run it from cron with -o, or as a daemon with -d.
|
101
|
+
|
102
|
+
See <tt>ar_sendmail -h</tt> for full details.
|
103
|
+
|
104
|
+
=== Using the --log-header option
|
105
|
+
|
106
|
+
Ever get complaints from customers who never got that email your system sent? Try this for a strategy:
|
107
|
+
|
108
|
+
1. When building the email, add the header "X-Delivery-Context: invite-#{invite.id}"
|
109
|
+
2. Launch ar_sendmail with --log-header X-Delivery-Context
|
110
|
+
3. When emails get sent, you can now associate the email SMTP message id with an record in your DB
|
111
|
+
|
112
|
+
So when customer X did not ever get invite 4, you now have the means of tracking invite 4 and find out exactly what happened.
|
113
|
+
|
114
|
+
=== Alternate Mail Storage
|
115
|
+
|
116
|
+
By default ar_mailer assumes you are using an ActiveRecord model called
|
117
|
+
Email to store the emails created before sending. If you want to change
|
118
|
+
this you alter it in an intializer like so:
|
119
|
+
|
120
|
+
ActionMailer::Base.email_class = Newsletter
|
121
|
+
|
122
|
+
=== A Word on TLS
|
123
|
+
|
124
|
+
If you are using Ruby >= 1.8.7, TLS will be enabled automatically if your
|
125
|
+
SMTP server supports it. If you do not want it to automatically enabled then
|
126
|
+
set the :tls option to false in your smtp_settings.
|
127
|
+
|
128
|
+
If you are on Ruby <= 1.8.6, then the TLS patch included in this plugin will
|
129
|
+
be loaded, so you don't need another TLS plugin to add the capability. This
|
130
|
+
patch allows you to explicit set if the server supports TLS by setting the
|
131
|
+
:tls option to true in your smtp_settings.
|
132
|
+
|
133
|
+
=== Help
|
134
|
+
|
135
|
+
See ar_sendmail -h for options to ar_sendmail.
|
136
|
+
|
137
|
+
NOTE: You may need to delete an smtp_tls.rb file if you have one lying
|
138
|
+
around. ar_mailer supplies it own.
|
139
|
+
|
140
|
+
== Run as a service (init.d/rc.d scripts)
|
141
|
+
|
142
|
+
For Linux both script and demo config files are in share/linux.
|
143
|
+
See ar_sendmail.conf for setting up your config. Copy the ar_sendmail file
|
144
|
+
to /etc/init.d/ and make it executable. Then for Debian based distros run
|
145
|
+
'sudo update-rc.d ar_sendmail defaults' and it should work. Make sure you have
|
146
|
+
the config file /etc/ar_sendmail.conf in place before starting.
|
147
|
+
|
148
|
+
For FreeBSD or NetBSD script is share/bsd/ar_sendmail. This is old and does not
|
149
|
+
support the config file unless someone wants to submit a patch.
|
data/Rakefile
CHANGED
@@ -8,23 +8,21 @@ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
|
|
8
8
|
require './lib/action_mailer/ar_sendmail'
|
9
9
|
|
10
10
|
ar_mailer_gemspec = Gem::Specification.new do |s|
|
11
|
-
s.name = %q{ar_mailer}
|
11
|
+
s.name = %q{zendesk-ar_mailer}
|
12
12
|
s.version = ActionMailer::ARSendmail::VERSION
|
13
13
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
14
|
-
s.authors = ["Eric Hodel"]
|
15
|
-
s.date = %q{2008-07-04}
|
14
|
+
s.authors = ["Eric Hodel", "Adam Meehan", "Morten Primdahl"]
|
16
15
|
s.default_executable = %q{ar_sendmail}
|
17
16
|
s.description = %q{Even delivering email to the local machine may take too long when you have to send hundreds of messages. ar_mailer allows you to store messages into the database for later delivery by a separate process, ar_sendmail.}
|
18
|
-
s.email = %q{
|
17
|
+
s.email = %q{adam.meehan@gmail.com}
|
19
18
|
s.executables = ["ar_sendmail"]
|
20
|
-
s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "
|
21
|
-
s.files = ["History.txt", "LICENSE.txt", "
|
19
|
+
s.extra_rdoc_files = ["History.txt", "LICENSE.txt", "README.rdoc"]
|
20
|
+
s.files = ["History.txt", "LICENSE.txt", "README.rdoc", "Rakefile", "bin/ar_sendmail", "generators/ar_mailer/ar_mailer_generator.rb", "generators/ar_mailer/templates/migration.rb", "generators/ar_mailer/templates/model.rb", "lib/action_mailer/ar_mailer.rb", "lib/action_mailer/ar_sendmail.rb", "lib/smtp_tls.rb", "lib/ar_sendmail_logger.rb", "share/bsd/ar_sendmail", "share/linux/ar_sendmail", "share/linux/ar_sendmail.conf", "test/resources/action_mailer.rb", "test/test_armailer.rb", "test/test_arsendmail.rb", "test/test_helper.rb"]
|
22
21
|
s.has_rdoc = true
|
23
|
-
s.homepage = %q{http://
|
24
|
-
s.rdoc_options = ["--main", "README.
|
22
|
+
s.homepage = %q{http://github.com/zendesk/ar_mailer}
|
23
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
25
24
|
s.require_paths = ["lib"]
|
26
25
|
s.rubyforge_project = %q{seattlerb}
|
27
|
-
s.rubygems_version = %q{1.2.0}
|
28
26
|
s.summary = %q{A two-phase delivery agent for ActionMailer}
|
29
27
|
s.test_files = ["test/test_armailer.rb", "test/test_arsendmail.rb"]
|
30
28
|
end
|
@@ -33,20 +31,16 @@ Rake::GemPackageTask.new(ar_mailer_gemspec) do |pkg|
|
|
33
31
|
pkg.gem_spec = ar_mailer_gemspec
|
34
32
|
end
|
35
33
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
File.open("ar_mailer.gemspec", "w") do |f|
|
41
|
-
f.puts(ar_mailer_gemspec.to_ruby)
|
42
|
-
end
|
43
|
-
end
|
34
|
+
desc "Update ar_mailer.gemspec"
|
35
|
+
task :make_spec do
|
36
|
+
File.open("ar_mailer.gemspec", "w") do |f|
|
37
|
+
f.puts(ar_mailer_gemspec.to_ruby)
|
44
38
|
end
|
45
39
|
end
|
46
40
|
|
47
41
|
desc "Build packages and install"
|
48
42
|
task :install => :package do
|
49
|
-
sh %{sudo gem install --local pkg/ar_mailer-#{ActionMailer::ARSendmail::VERSION}}
|
43
|
+
sh %{sudo gem install --local --test pkg/ar_mailer-#{ActionMailer::ARSendmail::VERSION}}
|
50
44
|
end
|
51
45
|
|
52
46
|
desc 'Default: run unit tests.'
|
@@ -55,6 +49,6 @@ task :default => :test
|
|
55
49
|
desc 'Test the ar_mailer gem.'
|
56
50
|
Rake::TestTask.new(:test) do |t|
|
57
51
|
t.libs << 'lib' << 'test'
|
58
|
-
t.
|
52
|
+
t.test_files = FileList['test/**/test_*.rb'].exclude("test/test_helper.rb")
|
59
53
|
t.verbose = true
|
60
54
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class ArMailerGenerator < Rails::Generator::NamedBase
|
2
|
+
|
3
|
+
def initialize(runtime_args, runtime_options = {})
|
4
|
+
runtime_args.unshift('Email') if runtime_args.empty?
|
5
|
+
super
|
6
|
+
end
|
7
|
+
|
8
|
+
def manifest
|
9
|
+
record do |m|
|
10
|
+
m.class_collisions class_name
|
11
|
+
|
12
|
+
m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
|
13
|
+
|
14
|
+
m.migration_template 'migration.rb', 'db/migrate', :assigns => {
|
15
|
+
:migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
|
16
|
+
}, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
protected
|
21
|
+
def banner
|
22
|
+
"Usage: #{$0} #{spec.name} EmailModelName (default: Email)"
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class <%= migration_name %> < ActiveRecord::Migration
|
2
|
+
def self.up
|
3
|
+
create_table :<%= table_name %> do |t|
|
4
|
+
t.column :from, :string
|
5
|
+
t.column :to, :string
|
6
|
+
t.column :last_send_attempt, :integer, :default => 0
|
7
|
+
t.column :mail, :text
|
8
|
+
t.column :created_on, :datetime
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.down
|
13
|
+
drop_table :<%= table_name %>
|
14
|
+
end
|
15
|
+
end
|
@@ -1,111 +1,31 @@
|
|
1
|
-
require 'action_mailer'
|
2
|
-
|
3
1
|
##
|
4
2
|
# Adds sending email through an ActiveRecord table as a delivery method for
|
5
3
|
# ActionMailer.
|
6
4
|
#
|
7
|
-
# == Converting to ActionMailer::ARMailer
|
8
|
-
#
|
9
|
-
# Go to your Rails project:
|
10
|
-
#
|
11
|
-
# $ cd your_rails_project
|
12
|
-
#
|
13
|
-
# Create a new migration:
|
14
|
-
#
|
15
|
-
# $ ar_sendmail --create-migration
|
16
|
-
#
|
17
|
-
# You'll need to redirect this into a file. If you want a different name
|
18
|
-
# provide the --table-name option.
|
19
|
-
#
|
20
|
-
# Create a new model:
|
21
|
-
#
|
22
|
-
# $ ar_sendmail --create-model
|
23
|
-
#
|
24
|
-
# You'll need to redirect this into a file. If you want a different name
|
25
|
-
# provide the --table-name option.
|
26
|
-
#
|
27
|
-
# Change your email classes to inherit from ActionMailer::ARMailer instead of
|
28
|
-
# ActionMailer::Base:
|
29
|
-
#
|
30
|
-
# --- app/model/emailer.rb.orig 2006-08-10 13:16:33.000000000 -0700
|
31
|
-
# +++ app/model/emailer.rb 2006-08-10 13:16:43.000000000 -0700
|
32
|
-
# @@ -1,4 +1,4 @@
|
33
|
-
# -class Emailer < ActionMailer::Base
|
34
|
-
# +class Emailer < ActionMailer::ARMailer
|
35
|
-
#
|
36
|
-
# def comment_notification(comment)
|
37
|
-
# from comment.author.email
|
38
|
-
#
|
39
|
-
# You'll need to be sure to set the From address for your emails. Something
|
40
|
-
# like:
|
41
|
-
#
|
42
|
-
# def list_send(recipient)
|
43
|
-
# from 'no_reply@example.com'
|
44
|
-
# # ...
|
45
|
-
#
|
46
|
-
# Edit config/environment.rb and require ar_mailer.rb:
|
47
|
-
#
|
48
|
-
# require 'action_mailer/ar_mailer'
|
49
|
-
#
|
50
|
-
# Edit config/environments/production.rb and set the delivery agent:
|
51
|
-
#
|
52
|
-
# $ grep delivery_method config/environments/production.rb
|
53
|
-
# ActionMailer::Base.delivery_method = :activerecord
|
54
|
-
#
|
55
|
-
# Run ar_sendmail:
|
56
|
-
#
|
57
|
-
# $ ar_sendmail
|
58
|
-
#
|
59
|
-
# You can also run it from cron with -o, or as a daemon with -d.
|
60
|
-
#
|
61
|
-
# See <tt>ar_sendmail -h</tt> for full details.
|
62
|
-
#
|
63
|
-
# == Alternate Mail Storage
|
64
|
-
#
|
65
|
-
# If you want to set the ActiveRecord model that emails will be stored in,
|
66
|
-
# see ActionMailer::ARMailer::email_class=
|
67
|
-
|
68
|
-
class ActionMailer::ARMailer < ActionMailer::Base
|
69
|
-
|
70
|
-
@@email_class = Email
|
71
5
|
|
72
|
-
|
73
|
-
# Current email class for deliveries.
|
74
|
-
|
75
|
-
def self.email_class
|
76
|
-
@@email_class
|
77
|
-
end
|
6
|
+
class ActionMailer::Base
|
78
7
|
|
79
8
|
##
|
80
|
-
#
|
9
|
+
# Set the email class for deliveries. Handle class reloading issues which prevents caching the email class.
|
10
|
+
#
|
11
|
+
@@email_class_name = 'Email'
|
81
12
|
|
82
13
|
def self.email_class=(klass)
|
83
|
-
@@
|
14
|
+
@@email_class_name = klass.to_s
|
84
15
|
end
|
85
16
|
|
86
|
-
|
87
|
-
|
88
|
-
def self.context_header
|
89
|
-
@@context_header
|
17
|
+
def self.email_class
|
18
|
+
@@email_class_name.constantize
|
90
19
|
end
|
91
|
-
|
20
|
+
|
92
21
|
##
|
93
22
|
# Adds +mail+ to the Email table. Only the first From address for +mail+ is
|
94
23
|
# used.
|
95
24
|
|
96
25
|
def perform_delivery_activerecord(mail)
|
97
26
|
mail.destinations.each do |destination|
|
98
|
-
|
99
|
-
if @@context_header && mail.header_string(@@context_header)
|
100
|
-
@@email_class.create(
|
101
|
-
:mail => mail.encoded, :to => destination,
|
102
|
-
:from => mail.from.first, :context => mail.header_string(@@context_header)
|
103
|
-
)
|
104
|
-
else
|
105
|
-
@@email_class.create(:mail => mail.encoded, :to => destination, :from => mail.from.first)
|
106
|
-
end
|
27
|
+
self.class.email_class.create :mail => mail.encoded, :to => destination, :from => mail.from.first
|
107
28
|
end
|
108
29
|
end
|
109
30
|
|
110
31
|
end
|
111
|
-
|