Class: AmazonSes::Mailer

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon-ses-mailer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Mailer

Returns a new instance of Mailer.



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/amazon-ses-mailer.rb', line 12

def initialize(opts)
  @version  = opts[:version]  || '2010-12-01'
  @endpoint = opts[:endpoint] || 'https://email.us-east-1.amazonaws.com/'
  @host     = opts[:host]     || 'email.us-east-1.amazonaws.com'
  
  raise "Access key needed" unless opts.key? :access_key
  raise "Secret key needed" unless opts.key? :secret_key
  
  @access_key = opts[:access_key]
  @secret_key = opts[:secret_key]
end

Instance Attribute Details

#settingsObject

Start ActionMailer-specific stuff #####



25
26
27
# File 'lib/amazon-ses-mailer.rb', line 25

def settings
  @settings
end

Instance Method Details

#deliver(msg) ⇒ Object

End ActionMailer-specific stuff #####



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/amazon-ses-mailer.rb', line 36

def deliver(msg)
  @time = Time.now
  
  if @endpoint.start_with? 'https'
    http = Net::HTTP.new(@host, 443)
    http.use_ssl = true
  else
    http = Net::HTTP.new(@host)
  end
  
  headers = { "x-amzn-authorization" => full_signature,
              "Date"                 => sig_timestamp }
              
  data = request_data(msg)

  http.post("/", data, headers).body
end

#deliver!(msg) ⇒ Object



31
32
33
# File 'lib/amazon-ses-mailer.rb', line 31

def deliver!(msg)
  deliver(msg)
end

#new(*args) ⇒ Object



27
28
29
# File 'lib/amazon-ses-mailer.rb', line 27

def new(*args)
  self
end