ynw-ar_mailer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,135 @@
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
+
55
+ = 1.4.3
56
+
57
+ * Bugs fixed
58
+ * Replaced mistaken call to log when removing pid file artifact for
59
+ non-running daemon
60
+
61
+ = 1.4.2
62
+
63
+ * New Features
64
+ * Added Ruby based linux init.d script for handling daemon startup using yaml
65
+ config file. See files share/linux/ar_sendmail and ar_sendmail.conf
66
+ * Bugs fixed
67
+ * Proper handling for relative and absolute paths for the pid file
68
+ * Removed hoe dependency since we need the explicit gemspec file for github and
69
+ not deploying to RubyForge its not as useful.
70
+ * Moved old BSD rc.d script to share/bsd folder
71
+ * Updated README with github gem install, docs and init script info
72
+
73
+ = 1.4.1
74
+
75
+ * Bugs fixed
76
+ * Daemon failed on startup fixed with expanding full path of pid file
77
+
78
+ = 1.4.0
79
+
80
+ * Forked gem and published on GitHub (gem sources -a http://gems.github.com)
81
+ * New Features
82
+ * Added pid file creation on daemonize with command line option to specify pid filename [Dylan Egan]
83
+
84
+ = 1.3.1
85
+
86
+ * Fix bug #12530, gmail causes SSL errors. Submitted by Kyle Maxwell
87
+ and Alex Ostleitner.
88
+ * Try ActionMailer::Base::server_settings then ::smtp_settings. Fixes
89
+ bug #12516. Submitted by Alex Ostleitner.
90
+
91
+ = 1.3.0
92
+
93
+ * New Features
94
+ * Added automatic mail queue cleanup.
95
+ * MAY CAUSE LOSS OF DATA. If you haven't run ar_sendmail within
96
+ the expiry time, set it to 0.
97
+ * Bugs fixed
98
+ * Authentication errors are now handled by retrying once.
99
+
100
+ = 1.2.0
101
+
102
+ * Bugs fixed
103
+ * Handle SMTPServerBusy by backing off @delay seconds then re-queueing
104
+ * Allow email delivery class to be set in ARMailer.
105
+ * ar_sendmail --mailq works with --table-name now.
106
+ * Miscellaneous Updates
107
+ * Added documentation to require 'action_mailer/ar_mailer' in
108
+ instructions.
109
+ * Moved to ZSS p4 repository
110
+ * Supports TLS now. Requested by Dave Thomas. smtp_tls.rb from Kyle
111
+ Maxwell & etc.
112
+
113
+ = 1.1.0
114
+
115
+ * Features
116
+ * Added --chdir to set rails directory
117
+ * Added --environment to set RAILS_ENV
118
+ * Exits cleanly on TERM or INT signals
119
+ * Added FreeBSD rc.d script
120
+ * Exceptions during SMTP sending are now logged
121
+ * No longer waits if sending email took too long
122
+ * Bugs fixed
123
+ * Fixed last send attempt in --mailq
124
+ * Better SMTP error handling
125
+ * Messages are removed from the queue on 5xx errors
126
+ * Added Net::SMTP.reset to avoid needing to recreate the connection
127
+
128
+ = 1.0.1
129
+
130
+ * Bugs fixed
131
+ * From and to of email destination were swapped
132
+
133
+ = 1.0.0
134
+
135
+ * Birthday
data/LICENSE.txt ADDED
@@ -0,0 +1,28 @@
1
+ Original code copyright 2006, 2007, Eric Hodel, The Robot Co-op. All
2
+ rights reserved. Some code under other license, see individual files
3
+ for details.
4
+
5
+ Redistribution and use in source and binary forms, with or without
6
+ modification, are permitted provided that the following conditions
7
+ are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright
10
+ notice, this list of conditions and the following disclaimer.
11
+ 2. Redistributions in binary form must reproduce the above copyright
12
+ notice, this list of conditions and the following disclaimer in the
13
+ documentation and/or other materials provided with the distribution.
14
+ 3. Neither the names of the authors nor the names of their contributors
15
+ may be used to endorse or promote products derived from this software
16
+ without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
19
+ OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE
22
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
23
+ OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
24
+ OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
25
+ BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26
+ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
27
+ OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
28
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.rdoc ADDED
@@ -0,0 +1,165 @@
1
+ = ar_mailer
2
+
3
+ A two-phase delivery agent for ActionMailer
4
+
5
+ GitHub Project:
6
+
7
+ http://rubyforge.org/projects/seattlerb
8
+
9
+ Documentation:
10
+
11
+ http://seattlerb.rubyforge.org/ar_mailer/
12
+
13
+ == About ar_mailer
14
+
15
+ Even delivering email to the local machine may take too long when you have to
16
+ send hundreds of messages. ar_mailer allows you to store messages into the
17
+ database for later delivery by a separate process, ar_sendmail.
18
+
19
+ == About this fork
20
+
21
+ GitHub Project:
22
+
23
+ http://github.com/artemv/ar_mailer
24
+
25
+ We didn't really needed ar_mailer - instead we wanted to digest error email notifications sent by ExceptionNotifier.
26
+ Sometimes Prod can face some issue that make it error like hell. There's no need to receive these errors one by one - we wanted them to be combined into digest periodically - in our case SMTP provider's tariff plan limits outgoing messages number. So we used adzap-ar_mailer for error messages buffering and then made it combine them to digests based on To field. Also we already had BackgrounDRB so we didn't need separate ar_sendmail process. So, what does this fork do out of the box:
27
+
28
+ * ARMailer messages don't get send until they are combined into digests
29
+
30
+ * all messages to same addressee are combined into one digest email
31
+
32
+ * it only supports text/plain messages
33
+
34
+ * if the digest mail is too big it gets truncated, and full digest is dumped to a file on server; truncated digest will tell about it
35
+
36
+ * the sending itself can be triggered by method call, so now you have options to use ar_sendmail process or smth else, e.g. BackgrounDRB job
37
+
38
+ * you can specify :smtp_settings to be used when sending digests: we needed it to be other than default ActionMailer::Base.smtp_settings
39
+
40
+ Usage example:
41
+
42
+ ActionMailer::ARSendmail.digest_error_emails :dump_path => '/var/log/myapp',
43
+ :subj_prefix => ExceptionNotifier.email_prefix,
44
+ :smtp_settings => {:address => "localhost",
45
+ :port => 25,
46
+ :domain => 'my_domain.com',
47
+ :tls => false,}
48
+
49
+ Adzap's fork is great because you can use ar_mailer for just one class with it - just what we needed. So we decided to opensource our tweaks in hope that it will be helpful for someone. The code is quite limited but it's fine for our needs, and if you need more you have smth to start with. E.g. it could be improved to support text/html messages or to make certain classes bypass digesting when sending emails with ARMailer.
50
+
51
+ The fork is contributed by Your Net Works, Inc.
52
+
53
+ == Installing ar_mailer (forked)
54
+
55
+ Before installing you will need to make sure the original gem is uninstalled as they can't coexist:
56
+
57
+ $ sudo gem uninstall ar_mailer
58
+
59
+ Install the gem from Gemcutter gems server:
60
+
61
+ First, if you haven't already:
62
+
63
+ $ sudo gem sources -a http://gemcutter.org
64
+
65
+ Then
66
+
67
+ $ sudo gem install ynw-ar_mailer
68
+
69
+ For Rails >= 2.1, in your environment.rb:
70
+
71
+ config.gem "ynw-ar_mailer", :lib => 'action_mailer/ar_mailer', :source => 'http://gemcutter.org'
72
+
73
+ For Rails 2.0, in an initializer file:
74
+
75
+ require 'action_mailer/ar_mailer'
76
+
77
+ == Usage
78
+
79
+ Go to your Rails project:
80
+
81
+ $ cd your_rails_project
82
+
83
+ Create the migration and model:
84
+
85
+ This shows the options which are only the model name, which defaults to Email
86
+
87
+ ./script/generate ar_mailer -h
88
+
89
+ Then run with defaults
90
+
91
+ ./script/generate ar_mailer
92
+
93
+ Or specify a custom model name
94
+
95
+ ./script/generate ar_mailer Newsletter
96
+
97
+ See Alternate Mail Storage if you use a custom model name
98
+
99
+ In your mailer class methods you must be sure to set the From address for your emails.
100
+ Something like:
101
+
102
+ def list_send(recipient)
103
+ from 'no_reply@example.com'
104
+ # ...
105
+
106
+ Edit config/environments/production.rb and set the delivery method:
107
+
108
+ config.action_mailer.delivery_method = :activerecord
109
+
110
+ Or if you need to, you can set each mailer class delivery method individually:
111
+
112
+ class MyMailer < ActionMailer::Base
113
+ self.delivery_method = :activerecord
114
+ end
115
+
116
+ This can be useful when using plugins like ExceptionNotification. Where it
117
+ might be foolish to tie the sending of the email alert to the database when the
118
+ database might be causing the exception being raised. In this instance you could
119
+ override ExceptionNofitier delivery method to be smtp or set the other
120
+ mailer classes to use ARMailer explicitly.
121
+
122
+ Then to run it:
123
+
124
+ $ ar_sendmail
125
+
126
+ You can also run it from cron with -o, or as a daemon with -d.
127
+
128
+ See <tt>ar_sendmail -h</tt> for full details.
129
+
130
+ === Alternate Mail Storage
131
+
132
+ By default ar_mailer assumes you are using an ActiveRecord model called
133
+ Email to store the emails created before sending. If you want to change
134
+ this you alter it in an intializer like so:
135
+
136
+ ActionMailer::Base.email_class = Newsletter
137
+
138
+ === A Word on TLS
139
+
140
+ If you are using Ruby >= 1.8.7, TLS will be enabled automatically if your
141
+ SMTP server supports it. If you do not want it to automatically enabled then
142
+ set the :tls option to false in your smtp_settings.
143
+
144
+ If you are on Ruby <= 1.8.6, then the TLS patch included in this plugin will
145
+ be loaded, so you don't need another TLS plugin to add the capability. This
146
+ patch allows you to explicit set if the server supports TLS by setting the
147
+ :tls option to true in your smtp_settings.
148
+
149
+ === Help
150
+
151
+ See ar_sendmail -h for options to ar_sendmail.
152
+
153
+ NOTE: You may need to delete an smtp_tls.rb file if you have one lying
154
+ around. ar_mailer supplies it own.
155
+
156
+ == Run as a service (init.d/rc.d scripts)
157
+
158
+ For Linux both script and demo config files are in share/linux.
159
+ See ar_sendmail.conf for setting up your config. Copy the ar_sendmail file
160
+ to /etc/init.d/ and make it executable. Then for Debian based distros run
161
+ 'sudo update-rc.d ar_sendmail defaults' and it should work. Make sure you have
162
+ the config file /etc/ar_sendmail.conf in place before starting.
163
+
164
+ For FreeBSD or NetBSD script is share/bsd/ar_sendmail. This is old and does not
165
+ support the config file unless someone wants to submit a patch.
data/Rakefile ADDED
@@ -0,0 +1,54 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rake/testtask'
4
+ require 'rake/rdoctask'
5
+
6
+ $:.unshift(File.expand_path(File.dirname(__FILE__) + '/lib'))
7
+
8
+ require './lib/action_mailer/ar_sendmail'
9
+
10
+ ar_mailer_gemspec = Gem::Specification.new do |s|
11
+ s.name = %q{ar_mailer}
12
+ s.version = ActionMailer::ARSendmail::VERSION
13
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
14
+ s.authors = ["Eric Hodel", "Adam Meehan"]
15
+ s.default_executable = %q{ar_sendmail}
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.}
17
+ s.email = %q{adam.meehan@gmail.com}
18
+ s.executables = ["ar_sendmail"]
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", "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"]
21
+ s.has_rdoc = true
22
+ s.homepage = %q{http://github.com/adzap/ar_mailer}
23
+ s.rdoc_options = ["--main", "README.rdoc"]
24
+ s.require_paths = ["lib"]
25
+ s.rubyforge_project = %q{seattlerb}
26
+ s.summary = %q{A two-phase delivery agent for ActionMailer}
27
+ s.test_files = ["test/test_armailer.rb", "test/test_arsendmail.rb"]
28
+ end
29
+
30
+ Rake::GemPackageTask.new(ar_mailer_gemspec) do |pkg|
31
+ pkg.gem_spec = ar_mailer_gemspec
32
+ end
33
+
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)
38
+ end
39
+ end
40
+
41
+ desc "Build packages and install"
42
+ task :install => :package do
43
+ sh %{sudo gem install --local --test pkg/ar_mailer-#{ActionMailer::ARSendmail::VERSION}}
44
+ end
45
+
46
+ desc 'Default: run unit tests.'
47
+ task :default => :test
48
+
49
+ desc 'Test the ar_mailer gem.'
50
+ Rake::TestTask.new(:test) do |t|
51
+ t.libs << 'lib' << 'test'
52
+ t.test_files = FileList['test/**/test_*.rb'].exclude("test/test_helper.rb")
53
+ t.verbose = true
54
+ end
data/bin/ar_sendmail ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'action_mailer/ar_sendmail'
4
+
5
+ ActionMailer::ARSendmail.run
6
+
@@ -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,16 @@
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
+ t.column :ready, :boolean, :default => 0, :null => false
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= table_name %>
15
+ end
16
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,31 @@
1
+ ##
2
+ # Adds sending email through an ActiveRecord table as a delivery method for
3
+ # ActionMailer.
4
+ #
5
+
6
+ class ActionMailer::Base
7
+
8
+ ##
9
+ # Set the email class for deliveries. Handle class reloading issues which prevents caching the email class.
10
+ #
11
+ @@email_class_name = 'Email'
12
+
13
+ def self.email_class=(klass)
14
+ @@email_class_name = klass.to_s
15
+ end
16
+
17
+ def self.email_class
18
+ @@email_class_name.constantize
19
+ end
20
+
21
+ ##
22
+ # Adds +mail+ to the Email table. Only the first From address for +mail+ is
23
+ # used.
24
+
25
+ def perform_delivery_activerecord(mail)
26
+ mail.destinations.each do |destination|
27
+ self.class.email_class.create :mail => mail.encoded, :to => destination, :from => mail.from.first
28
+ end
29
+ end
30
+
31
+ end