mailhopper 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +69 -0
- data/Rakefile +39 -0
- data/app/mailers/mailhopper/mailer.rb +4 -0
- data/app/models/mailhopper/email.rb +17 -0
- data/config/routes.rb +2 -0
- data/lib/generators/mailhopper/mailhopper_generator.rb +36 -0
- data/lib/generators/mailhopper/templates/README +28 -0
- data/lib/generators/mailhopper/templates/initializer.rb +3 -0
- data/lib/generators/mailhopper/templates/migrations/create_emails.rb +21 -0
- data/lib/mailhopper.rb +13 -0
- data/lib/mailhopper/base.rb +19 -0
- data/lib/mailhopper/engine.rb +4 -0
- data/lib/mailhopper/queue.rb +18 -0
- data/lib/mailhopper/version.rb +3 -0
- data/lib/tasks/mailhopper_tasks.rake +4 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +9 -0
- data/test/dummy/app/assets/stylesheets/application.css +7 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/mailers/sample_mailer.rb +8 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/sample_mailer/hello.text.erb +1 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +42 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +27 -0
- data/test/dummy/config/environments/production.rb +51 -0
- data/test/dummy/config/environments/test.rb +39 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +10 -0
- data/test/dummy/config/initializers/mailhopper.rb +3 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +12 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +58 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20110801151741_create_emails.rb +21 -0
- data/test/dummy/db/schema.rb +28 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +50 -0
- data/test/dummy/log/test.log +398 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/mailhopper_test.rb +7 -0
- data/test/test_helper.rb +14 -0
- data/test/unit/email_test.rb +50 -0
- metadata +207 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2011 Cerebris Corporation
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
= Mailhopper
|
2
|
+
|
3
|
+
Mailhopper provides an ActiveRecord based queue for email storage and delivery in Rails apps.
|
4
|
+
|
5
|
+
Why use Mailhopper to queue your email?
|
6
|
+
* Mailhopper captures the full content and headers of emails at their time of creation. It can handle multiple MIME types and attachments.
|
7
|
+
* If email can't be delivered from your queue (e.g. your smtp server is down), you can retry delivery until successful.
|
8
|
+
* Emails can be accessed at any time, even after they've been sent.
|
9
|
+
|
10
|
+
Mailhopper is intended to be used along with a delivery agent such as DelayedMailhopper, which uses DelayedJob to deliver email from the Mailhopper queue. Without use of a delivery agent, emails will accumulate in the Mailhopper queue but won't be delivered.
|
11
|
+
|
12
|
+
== Requirements
|
13
|
+
|
14
|
+
Rails 3.1+
|
15
|
+
|
16
|
+
== Installation
|
17
|
+
|
18
|
+
Add to your project's Gemfile:
|
19
|
+
|
20
|
+
gem 'mailhopper'
|
21
|
+
|
22
|
+
Install with bundler:
|
23
|
+
|
24
|
+
bundle install
|
25
|
+
|
26
|
+
Generate default initializer and migration files:
|
27
|
+
|
28
|
+
rails generate mailhopper
|
29
|
+
|
30
|
+
Migrate your database:
|
31
|
+
|
32
|
+
rake db:migrate
|
33
|
+
|
34
|
+
!!! Don't forget to also install a delivery agent, such as DelayedMailhopper, so that emails will be delivered from your queue !!!
|
35
|
+
|
36
|
+
== Configuration
|
37
|
+
|
38
|
+
If you want all of your application's email to be queued in Mailhopper, configure mailers either in environment.rb or your application's environment-specific configuration files:
|
39
|
+
|
40
|
+
MyApp::Application.configure do
|
41
|
+
config.action_mailer.delivery_method = :mailhopper
|
42
|
+
end
|
43
|
+
|
44
|
+
Alternatively, or additionally, configure individual mailers to use Mailhopper:
|
45
|
+
|
46
|
+
class MyMailer < ActionMailer::Base
|
47
|
+
ActionMailer::Base.delivery_method = :mailhopper
|
48
|
+
end
|
49
|
+
|
50
|
+
== Options
|
51
|
+
|
52
|
+
The following options can be configured in your initializer (config/initializers/mailhopper):
|
53
|
+
|
54
|
+
Mailhopper::Base.setup do |config|
|
55
|
+
# The base email class used by Mailhopper
|
56
|
+
config.email_class = Mailhopper::Email
|
57
|
+
|
58
|
+
# The base mailer class used by Mailhopper
|
59
|
+
config.mailer_class = Mailhopper::Mailer
|
60
|
+
|
61
|
+
# The method used by the delivery agent to deliver emails from your queue
|
62
|
+
config.default_delivery_method = :smtp
|
63
|
+
end
|
64
|
+
|
65
|
+
It's preferable to leave these options out of your initializer if the defaults, shown above, are acceptable. Delivery agents may override some defaults (e.g. DelayedMailhopper sets email_class = DelayedMailhopper::Email).
|
66
|
+
|
67
|
+
== Copyright
|
68
|
+
|
69
|
+
Copyright (c) 2011 Cerebris Corporation. This is free software released under the MIT License (see MIT-LICENSE for details).
|
data/Rakefile
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'Mailhopper'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
24
|
+
load 'rails/tasks/engine.rake'
|
25
|
+
|
26
|
+
|
27
|
+
Bundler::GemHelper.install_tasks
|
28
|
+
|
29
|
+
require 'rake/testtask'
|
30
|
+
|
31
|
+
Rake::TestTask.new(:test) do |t|
|
32
|
+
t.libs << 'lib'
|
33
|
+
t.libs << 'test'
|
34
|
+
t.pattern = 'test/**/*_test.rb'
|
35
|
+
t.verbose = false
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
task :default => :test
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Mailhopper
|
2
|
+
class Email < ActiveRecord::Base
|
3
|
+
default_scope :order => 'created_at DESC'
|
4
|
+
scope :unsent, :conditions => 'sent_at is null'
|
5
|
+
|
6
|
+
validates :from_address, :presence => true
|
7
|
+
|
8
|
+
def send!(delivery_method = nil)
|
9
|
+
mail = Mail.new(self.content)
|
10
|
+
mail[:bcc] = self.bcc_address unless self.bcc_address.blank?
|
11
|
+
Base.mailer_class.wrap_delivery_behavior(mail, delivery_method || Base.default_delivery_method)
|
12
|
+
mail.deliver
|
13
|
+
self.sent_at = Time.now
|
14
|
+
self.save!
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
require 'rails/generators/migration'
|
3
|
+
|
4
|
+
module Mailhopper
|
5
|
+
module Generators
|
6
|
+
class MailhopperGenerator < Rails::Generators::Base
|
7
|
+
include Rails::Generators::Migration
|
8
|
+
|
9
|
+
desc 'Generates Mailhopper files.'
|
10
|
+
|
11
|
+
def self.source_root
|
12
|
+
File.join(File.dirname(__FILE__), 'templates')
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.next_migration_number(dirname)
|
16
|
+
if ActiveRecord::Base.timestamped_migrations
|
17
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
18
|
+
else
|
19
|
+
"%.3d" % (current_migration_number(dirname) + 1)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def create_migration_file
|
24
|
+
migration_template 'migrations/create_emails.rb', 'db/migrate/create_emails.rb'
|
25
|
+
end
|
26
|
+
|
27
|
+
def copy_initializer
|
28
|
+
template 'initializer.rb', 'config/initializers/mailhopper.rb'
|
29
|
+
end
|
30
|
+
|
31
|
+
def show_readme
|
32
|
+
readme 'README' if behavior == :invoke
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
|
2
|
+
===============================================================================
|
3
|
+
Mailhopper has been installed.
|
4
|
+
===============================================================================
|
5
|
+
|
6
|
+
To configure your application to use Mailhopper:
|
7
|
+
|
8
|
+
1) Migrate your database with "rake db:migrate".
|
9
|
+
|
10
|
+
2) Configure mailers either in environment.rb or environment-specific config files:
|
11
|
+
|
12
|
+
MyApp::Application.configure do
|
13
|
+
config.action_mailer.delivery_method = :mailhopper
|
14
|
+
end
|
15
|
+
|
16
|
+
Alternatively, or additionally, you can configure individual mailers:
|
17
|
+
|
18
|
+
class MyMailer < ActionMailer::Base
|
19
|
+
ActionMailer::Base.delivery_method = :mailhopper
|
20
|
+
end
|
21
|
+
|
22
|
+
3) Install a delivery agent, such as DelayedMailhopper, so that emails will be delivered from your queue.
|
23
|
+
|
24
|
+
4) Configure a delivery method in "config/initializers/mailhopper" for your delivery agent to use (the default is smtp).
|
25
|
+
|
26
|
+
Mailhopper::Base.setup do |config|
|
27
|
+
config.default_delivery_method = :smtp
|
28
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# Everything listed in this migration will be added to a migration file
|
2
|
+
# inside of your main app.
|
3
|
+
class CreateEmails < ActiveRecord::Migration
|
4
|
+
def self.up
|
5
|
+
create_table :emails do |t|
|
6
|
+
t.string :from_address, :null => false
|
7
|
+
t.string :to_address,
|
8
|
+
:cc_address,
|
9
|
+
:bcc_address,
|
10
|
+
:reply_to_address,
|
11
|
+
:subject
|
12
|
+
t.text :content
|
13
|
+
t.datetime :sent_at
|
14
|
+
t.timestamps
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.down
|
19
|
+
drop_table :emails
|
20
|
+
end
|
21
|
+
end
|
data/lib/mailhopper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "mailhopper/engine"
|
2
|
+
require 'mailhopper/queue'
|
3
|
+
require 'mailhopper/base'
|
4
|
+
|
5
|
+
module Mailhopper
|
6
|
+
class << self
|
7
|
+
def setup(&block)
|
8
|
+
Mailhopper::Base.setup(&block)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
ActionMailer::Base.add_delivery_method :mailhopper, Mailhopper::Queue
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../../../app/models/mailhopper/email', __FILE__)
|
2
|
+
require File.expand_path('../../../app/mailers/mailhopper/mailer', __FILE__)
|
3
|
+
|
4
|
+
module Mailhopper
|
5
|
+
class Base
|
6
|
+
cattr_accessor :email_class
|
7
|
+
self.email_class = Mailhopper::Email
|
8
|
+
|
9
|
+
cattr_accessor :mailer_class
|
10
|
+
self.mailer_class = Mailhopper::Mailer
|
11
|
+
|
12
|
+
cattr_accessor :default_delivery_method
|
13
|
+
self.default_delivery_method = :smtp
|
14
|
+
|
15
|
+
def self.setup
|
16
|
+
yield self
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Mailhopper
|
2
|
+
class Queue
|
3
|
+
def initialize(options)
|
4
|
+
end
|
5
|
+
|
6
|
+
def deliver!(mail)
|
7
|
+
Base.email_class.create({
|
8
|
+
:to_address => mail.to.to_s,
|
9
|
+
:from_address => mail.from.to_s,
|
10
|
+
:cc_address => mail.cc.to_s,
|
11
|
+
:bcc_address => mail.bcc.to_s,
|
12
|
+
:reply_to_address => mail.reply_to.to_s,
|
13
|
+
:subject => mail.subject,
|
14
|
+
:content => mail.to_s
|
15
|
+
})
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/test/dummy/Rakefile
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
# Add your own tasks in files placed in lib/tasks ending in .rake,
|
3
|
+
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
|
4
|
+
|
5
|
+
require File.expand_path('../config/application', __FILE__)
|
6
|
+
|
7
|
+
Dummy::Application.load_tasks
|
@@ -0,0 +1,9 @@
|
|
1
|
+
// This is a manifest file that'll be compiled into including all the files listed below.
|
2
|
+
// Add new JavaScript/Coffee code in separate files in this directory and they'll automatically
|
3
|
+
// be included in the compiled file accessible from http://example.com/assets/application.js
|
4
|
+
// It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
|
5
|
+
// the compiled file.
|
6
|
+
//
|
7
|
+
//= require jquery
|
8
|
+
//= require jquery_ujs
|
9
|
+
//= require_tree .
|
@@ -0,0 +1,7 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll automatically include all the stylesheets available in this directory
|
3
|
+
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
|
4
|
+
* the top of the compiled file, but it's generally better to create a new file per style scope.
|
5
|
+
*= require_self
|
6
|
+
*= require_tree .
|
7
|
+
*/
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= @content %>
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
Bundler.require
|
6
|
+
require "mailhopper"
|
7
|
+
|
8
|
+
module Dummy
|
9
|
+
class Application < Rails::Application
|
10
|
+
# Settings in config/environments/* take precedence over those specified here.
|
11
|
+
# Application configuration should go into files in config/initializers
|
12
|
+
# -- all .rb files in that directory are automatically loaded.
|
13
|
+
|
14
|
+
# Custom directories with classes and modules you want to be autoloadable.
|
15
|
+
# config.autoload_paths += %W(#{config.root}/extras)
|
16
|
+
|
17
|
+
# Only load the plugins named here, in the order given (default is alphabetical).
|
18
|
+
# :all can be used as a placeholder for all plugins not explicitly named.
|
19
|
+
# config.plugins = [ :exception_notification, :ssl_requirement, :all ]
|
20
|
+
|
21
|
+
# Activate observers that should always be running.
|
22
|
+
# config.active_record.observers = :cacher, :garbage_collector, :forum_observer
|
23
|
+
|
24
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
25
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
26
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
27
|
+
|
28
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
29
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
30
|
+
# config.i18n.default_locale = :de
|
31
|
+
|
32
|
+
# Configure the default encoding used in templates for Ruby 1.9.
|
33
|
+
config.encoding = "utf-8"
|
34
|
+
|
35
|
+
# Configure sensitive parameters which will be filtered from the log file.
|
36
|
+
config.filter_parameters += [:password]
|
37
|
+
|
38
|
+
# Enable the asset pipeline
|
39
|
+
config.assets.enabled = true
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|