Class: Mailit::Mailer
- Inherits:
-
Object
- Object
- Mailit::Mailer
- Defined in:
- lib/mailit/mailer.rb
Overview
The Mailer is an abstraction layer for different SMTP clients, it provides #send and #defer_send methods
At the time of writing, Net::SMTP and EventMachine::Protocols::SmtpClient are supported, it should be trivial to add support for any other client.
The difference between #send and #defer_send depends on the backend, but usually #send will block until the mail was sent while #defer_send does it in the background and allows you to continue execution immediately.
The default Mailer backend is Net::SMTP, you can change the default by including another module into Mailit::mailer
Defined Under Namespace
Modules: EventMachine
Constant Summary collapse
- OPTIONS =
{ :server => 'smtp.localhost', :port => 25, :domain => 'localhost', :username => '', :password => 'foo', :noop => false, :auth_type => :login, # :plain, :login, :cram_md5 :starttls => false, # only useful for EventMachine::SmtpClient }
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #defer_send(mail, override = {}) ⇒ Object
-
#initialize(options = {}) ⇒ Mailer
constructor
A new instance of Mailer.
- #send(mail, override = {}) ⇒ Object
Constructor Details
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
56 57 58 |
# File 'lib/mailit/mailer.rb', line 56 def @options end |
Class Method Details
.defer_send(mail, options = {}) ⇒ Object
52 53 54 |
# File 'lib/mailit/mailer.rb', line 52 def self.defer_send(mail, = {}) new.defer_send(mail, ) end |
.send(mail, options = {}) ⇒ Object
48 49 50 |
# File 'lib/mailit/mailer.rb', line 48 def self.send(mail, = {}) new.send(mail, ) end |
Instance Method Details
#defer_send(mail, override = {}) ⇒ Object
76 77 78 |
# File 'lib/mailit/mailer.rb', line 76 def defer_send(mail, override = {}) Thread.new{ send(mail, override) } end |
#send(mail, override = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/mailit/mailer.rb', line 62 def send(mail, override = {}) require 'net/smtp' mailer = override[:mailer] || ::Net::SMTP server, port, domain, username, password, auth_type, noop = settings(override, :server, :port, :domain, :username, :password, :auth_type, :noop) username = mail.from.to_s if !username.nil? && username.empty? mailer.start(server, port, domain, username, password, auth_type) do |smtp| return if noop smtp.(mail.to_s, mail.from, mail.to) end end |