Sha256: 35b205f2014ca9cfbae2f5c043fb9f1b75dc0e02146cdc4b8c6ec9e73365d8b9

Contents?: true

Size: 1.84 KB

Versions: 18

Compression:

Stored size: 1.84 KB

Contents

# frozen_string_literal: true
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

18 entries across 17 versions & 6 rubygems

Version Path
tdiary-5.0.5 vendor/bundle/gems/tdiary-5.0.4/vendor/bundle/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
tdiary-5.0.5 vendor/bundle/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/mail-2.6.5/lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.6.5 lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.6.5.rc1 lib/mail/network/delivery_methods/smtp_connection.rb
tdiary-5.0.4 vendor/bundle/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
autocompl-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
abaci-0.3.0 vendor/bundle/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
tdiary-5.0.2 vendor/bundle/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
tdiary-5.0.1 vendor/bundle/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
ish_lib_manager-0.0.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/mail-2.6.4/lib/mail/network/delivery_methods/smtp_connection.rb
mail-2.6.4 lib/mail/network/delivery_methods/smtp_connection.rb