Skip to content
Browse files

Allow the mailer class to be configured.

  • Loading branch information...
1 parent c4a4032 commit a2f84852af504df8c93c0b0f1afff7f76601b400 @josevalim josevalim committed Jun 12, 2010
View
1 CHANGELOG.rdoc
@@ -6,6 +6,7 @@
* Added authenticate(scope) support in routes (by github.com/wildchild)
* Added after_update_path_for to registrations controller (by github.com/thedelchop)
* Added anybody_signed_in? helper (by github.com/SSDany)
+ * Allow the mailer object to be replaced through config.mailer = "MyOwnMailer"
* bug fix
* confirmation_required? is properly honored on active? calls. (by github.com/paulrosania)
View
12 lib/devise.rb
@@ -1,4 +1,5 @@
require 'active_support/core_ext/numeric/time'
+require 'active_support/dependencies'
module Devise
autoload :FailureApp, 'devise/failure_app'
@@ -161,6 +162,17 @@ def self.setup
yield self
end
+ # Get the mailer class from the mailer reference object.
+ def self.mailer
+ @@mailer_ref.get
+ end
+
+ # Set the mailer reference object to access the mailer.
+ def self.mailer=(class_name)
+ @@mailer_ref = ActiveSupport::Dependencies.ref(class_name)
+ end
+ self.mailer = "Devise::Mailer"
+
# Register a model in Devise. You can call this manually if you don't want
# to use devise routes. Check devise_for in routes to know which options
# are available.
View
2 lib/devise/models/confirmable.rb
@@ -51,7 +51,7 @@ def confirmed?
# Send confirmation instructions by email
def send_confirmation_instructions
generate_confirmation_token if self.confirmation_token.nil?
- ::Devise::Mailer.confirmation_instructions(self).deliver
+ ::Devise.mailer.confirmation_instructions(self).deliver
end
# Resend confirmation token. This method does not need to generate a new token.
View
2 lib/devise/models/lockable.rb
@@ -49,7 +49,7 @@ def access_locked?
# Send unlock instructions by email
def send_unlock_instructions
- ::Devise::Mailer.unlock_instructions(self).deliver
+ ::Devise.mailer.unlock_instructions(self).deliver
end
# Resend the unlock instructions if the user is locked.
View
2 lib/devise/models/recoverable.rb
@@ -28,7 +28,7 @@ def reset_password!(new_password, new_password_confirmation)
# Resets reset password token and send reset password instructions by email
def send_reset_password_instructions
generate_reset_password_token!
- ::Devise::Mailer.reset_password_instructions(self).deliver
+ ::Devise.mailer.reset_password_instructions(self).deliver
end
protected
View
4 lib/generators/devise_install/templates/devise.rb
@@ -1,9 +1,13 @@
# Use this hook to configure devise mailer, warden hooks and so forth. The first
# four configuration values can also be set straight in your models.
Devise.setup do |config|
+ # ==> Mailer Configuration
# Configure the e-mail address which will be shown in DeviseMailer.
config.mailer_sender = "please-change-me@config-initializers-devise.com"
+ # Configure the class responsible to send e-mails.
+ # config.mailer = "Devise::Mailer"
+
# ==> ORM configuration
# Load and configure the ORM. Supports :active_record (default), :mongoid
# (bson_ext recommended) and :data_mapper (experimental).

0 comments on commit a2f8485

Please sign in to comment.
Something went wrong with that request. Please try again.