Class: ActionMailer::Base
- Inherits:
-
Object
- Object
- ActionMailer::Base
- Defined in:
- lib/action_mailer/ar_mailer.rb
Overview
Adds sending email through an ActiveRecord table as a delivery method for ActionMailer.
Constant Summary collapse
- @@email_class_name =
Set the email class for deliveries. Handle class reloading issues which prevents caching the email class.
'Email'
Class Method Summary collapse
Instance Method Summary collapse
-
#perform_delivery_activerecord(mail) ⇒ Object
Adds
mail
to the Email table. - #perform_delivery_smtp(mail) ⇒ Object
- #perform_delivery_smtp_failover_activerecord(mail) ⇒ Object
Class Method Details
.email_class ⇒ Object
19 20 21 |
# File 'lib/action_mailer/ar_mailer.rb', line 19 def self.email_class @@email_class_name.constantize end |
.email_class=(klass) ⇒ Object
15 16 17 |
# File 'lib/action_mailer/ar_mailer.rb', line 15 def self.email_class=(klass) @@email_class_name = klass.to_s end |
Instance Method Details
#perform_delivery_activerecord(mail) ⇒ Object
Adds mail
to the Email table. Only the first From address for mail
is used.
27 28 29 30 31 |
# File 'lib/action_mailer/ar_mailer.rb', line 27 def perform_delivery_activerecord(mail) mail.destinations.each do |destination| self.class.email_class.create :mail => mail.encoded, :to => destination, :from => Array(mail.from).first end end |
#perform_delivery_smtp(mail) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/action_mailer/ar_mailer.rb', line 33 def perform_delivery_smtp(mail) destinations = mail.destinations mail.ready_to_send # via https://rails.lighthouseapp.com/projects/8994/tickets/2340 # via http://github.com/rails/rails/commit/da61a6c9671239dbb4a926c3e161ca8663fa0e3f sender = (mail['return-path'] && mail['return-path'].spec) || Array(mail.from).first user_names = (smtp_settings[:user] || smtp_settings[:user_name]).to_a settings = [ smtp_settings[:domain], user_names[rand(user_names.size)], smtp_settings[:password], smtp_settings[:authentication] ] smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port]) if smtp.respond_to?(:enable_starttls_auto) smtp.enable_starttls_auto unless smtp_settings[:tls] == false else settings << smtp_settings[:tls] end smtp.start(*settings) do |smtp| smtp.sendmail(mail.encoded, sender, destinations) end end |
#perform_delivery_smtp_failover_activerecord(mail) ⇒ Object
60 61 62 63 64 65 66 67 |
# File 'lib/action_mailer/ar_mailer.rb', line 60 def perform_delivery_smtp_failover_activerecord(mail) perform_delivery_smtp mail rescue Exception => e perform_delivery_activerecord mail logger.error e e.backtrace.each { |line| logger.error line} after_failed_delivery_smtp_mail(e) if defined? self.after_failed_delivery_smtp_mail end |