Class: Mailing::SmtpChannel
- Inherits:
-
BaseChannel
- Object
- BaseChannel
- Mailing::SmtpChannel
- Defined in:
- lib/mailing/smtp_channel.rb
Instance Attribute Summary
Attributes inherited from BaseChannel
Instance Method Summary collapse
- #deliver(mail, envelope_from, recipient) ⇒ Object
- #finish ⇒ Object
-
#initialize(config) ⇒ SmtpChannel
constructor
config: hash with smtp configuration { :address => “host.domain.com”, :port => 25, :domain => ‘domain.com’, :user_name => ‘[email protected]’, :password => ‘password’, :authentication => :login, :enable_starttls_auto => true, :openssl_verify_mode => ‘none’ }.
- #start ⇒ Object
Constructor Details
#initialize(config) ⇒ SmtpChannel
config: hash with smtp configuration
:address => "host.domain.com",
:port => 25,
:domain => 'domain.com',
:user_name => '[email protected]',
:password => 'password',
:authentication => :login,
:enable_starttls_auto => true,
:openssl_verify_mode => 'none'
18 19 20 21 |
# File 'lib/mailing/smtp_channel.rb', line 18 def initialize(config) super @smtp = nil end |
Instance Method Details
#deliver(mail, envelope_from, recipient) ⇒ Object
30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mailing/smtp_channel.rb', line 30 def deliver(mail, envelope_from, recipient) begin @smtp.sendmail(mail, envelope_from, recipient) "Sent to #{recipient}" rescue Exception => e finish start "Error for #{recipient}: #{e}".strip end end |
#finish ⇒ Object
41 42 43 |
# File 'lib/mailing/smtp_channel.rb', line 41 def finish @smtp.finish end |
#start ⇒ Object
23 24 25 26 27 28 |
# File 'lib/mailing/smtp_channel.rb', line 23 def start @smtp = Net::SMTP.new(@config[:address], @config[:port]) @smtp.enable_starttls_auto if @config[:enable_starttls_auto] @smtp.start(@config[:domain], @config[:user_name], @config[:password], @config[:authentication]) end |