Sha256: 25f9fdb898d6aee96a3073289ccc0dc60d3e2a0cf61c0eeef8d419fd7fee15f5

Contents?: true

Size: 1.82 KB

Versions: 19

Compression:

Stored size: 1.82 KB

Contents

require 'mail/check_delivery_params'

module Mail
  # == Sending Email with SMTP
  # 
  # Mail allows you to send emails using an open SMTP connection.  This is done by
  # passing a created Net::SMTP object.  This way we can get better performance to
  # our local mail server by reducing the number of connections at any one time.
  #
  # === Sending via SMTP server on Localhost
  # 
  # To send mail open a connection with Net::Smtp using any options you like
  # === Delivering the email
  # 
  # Once you have the settings right, sending the email is done by:
  #
  #   smtp_conn = Net::SMTP.start(settings[:address], settings[:port])
  #   Mail.defaults do
  #     delivery_method :smtp_connection, { :connection => smtp_conn }
  #   end
  # 
  #   Mail.deliver do
  #     to 'mikel@test.lindsaar.net'
  #     from 'ada@test.lindsaar.net'
  #     subject 'testing sendmail'
  #     body 'testing sendmail'
  #   end
  # 
  # Or by calling deliver on a Mail message
  # 
  #   mail = Mail.new do
  #     to 'mikel@test.lindsaar.net'
  #     from 'ada@test.lindsaar.net'
  #     subject 'testing sendmail'
  #     body 'testing sendmail'
  #   end
  # 
  #   mail.deliver!
  class SMTPConnection
    include Mail::CheckDeliveryParams

    def initialize(values)
      raise ArgumentError.new('A Net::SMTP object is required for this delivery method') if values[:connection].nil?
      self.smtp = values[:connection]
      self.settings = values
    end

    attr_accessor :smtp
    attr_accessor :settings

    # Send the message via SMTP.
    # The from and to attributes are optional. If not set, they are retrieve from the Message.
    def deliver!(mail)
      smtp_from, smtp_to, message = check_delivery_params(mail)
      response = smtp.sendmail(message, smtp_from, smtp_to)

      settings[:return_response] ? response : self
    end

  end
end

Version data entries

19 entries across 18 versions & 9 rubygems

Version Path
mail-2.6.4.rc2 lib/mail/network/delivery_methods/smtp_connection.rb
angular-rails4-templates-0.4.1 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
angular-rails4-templates-0.4.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
tdiary-4.2.1 vendor/bundle/ruby/2.3.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
tdiary-4.2.1 vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
angular-rails4-templates-0.3.0 vendor/ruby/2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.6.4.rc1 lib/mail/network/delivery_methods/smtp_connection.rb
sc_core-0.0.7 test/dummy/vendor/bundle/ruby/2.2.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
solidus_backend-1.0.0.pre3 vendor/bundle/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
solidus_backend-1.0.0.pre2 vendor/bundle/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
solidus_backend-1.0.0.pre vendor/bundle/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
shoppe-paypal-1.1.0 vendor/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.6.3 lib/mail/network/delivery_methods/smtp_connection.rb
mail-portertech-2.6.2.edge lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.6.1 lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.6.0 lib/mail/network/delivery_methods/smtp_connection.rb
challah-1.0.0 vendor/bundle/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp_connection.rb
swipe-rails-0.0.5 vendor/bundle/gems/mail-2.5.4/lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.5.4 lib/mail/network/delivery_methods/smtp_connection.rb