Sha256: 0a297f4ed2be8025a79090484624bce7a7a592d43c75dc11565e4199dc096f6b

Contents?: true

Size: 1.78 KB

Versions: 1

Compression:

Stored size: 1.78 KB

Contents

require 'smtp_tls' unless Net::SMTP.instance_methods.include?("enable_starttls_auto")

##
# Adds sending email through an ActiveRecord table as a delivery method for
# ActionMailer.
#

class ActionMailer::Base

  ##
  # Set the email class for deliveries. Handle class reloading issues which prevents caching the email class.
  #
  @@email_class_name = 'Email'

  def self.email_class=(klass)
    @@email_class_name = klass.to_s
  end

  def self.email_class
    @@email_class_name.constantize
  end

  ##
  # Adds +mail+ to the Email table.  Only the first From address for +mail+ is
  # used.

  def perform_delivery_activerecord(mail)
    mail.destinations.each do |destination|
      self.class.email_class.create :mail => mail.encoded, :to => destination, :from => mail.from.first
    end
  end

  def perform_delivery_smtp(mail)
    destinations = mail.destinations
    mail.ready_to_send
    sender = (mail['return-path'] && mail['return-path'].spec) || mail['from']

    settings = [
      smtp_settings[:domain],
      (smtp_settings[:user] || smtp_settings[:user_name]),
      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

  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

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
maedana-ar_mailer-2.1.5.1 lib/action_mailer/ar_mailer.rb