Class: Em::Mailer::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/em-mailer/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(values) ⇒ Client

Returns a new instance of Client.



7
8
9
10
11
12
13
14
# File 'lib/em-mailer/client.rb', line 7

def initialize(values)
  self.settings = {
    :host             => 'localhost',
    :port             => 5600,
    :delivery_method  => :sendmail,
    :delivery_options => {}
  }.merge!(values)
end

Instance Attribute Details

#settingsObject

Returns the value of attribute settings.



16
17
18
# File 'lib/em-mailer/client.rb', line 16

def settings
  @settings
end

Instance Method Details

#deliver!(mail) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/em-mailer/client.rb', line 18

def deliver!(mail)
  socket = open_socket
  Yajl::Encoder.encode({
    :message          => mail.to_s,
    :delivery_method  => settings[:delivery_method],
    :delivery_options => settings[:delivery_options]
  }, socket)
  socket.close
end

#open_socketObject



28
29
30
# File 'lib/em-mailer/client.rb', line 28

def open_socket
  TCPSocket.new(settings[:host], settings[:port])
end