Class: AmazonSES::AmzMail

Inherits:
Object
  • Object
show all
Defined in:
lib/amazon_ses/amz_mail.rb

Class Method Summary collapse

Class Method Details

.send(source, to_addresses, subject, body, secret, key) ⇒ Object



5
6
7
8
9
10
11
# File 'lib/amazon_ses/amz_mail.rb', line 5

def self.send(source,to_addresses,subject,body,secret,key)
  AmazonSES::Base.make_request({"Action"=>"SendEmail",
                                "Source"=>source,
                                "Destination.ToAddresses.member.1"=>to_addresses,
                                "Message.Subject.Data"=>subject,
                                "Message.Body.Text.Data"=>body},secret,key)
end

.send_html(source, to_addresses, subject_txt, body_txt, secret, key) ⇒ Object

This will construct and send a raw email message will send unless quota is reached. If quota is reached it will raise an exception. It takes two api calls to send an email.…



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/amazon_ses/amz_mail.rb', line 15

def self.send_html(source,to_addresses,subject_txt,body_txt,secret,key)
  if AmazonSES::StatObject.new(secret,key).reached_quota?
    raise "Sorry you have reached your quota."
  else
    mail = Mail.new do
      to to_addresses
      from source
      subject subject_txt
      html_part do
        content_type 'text/html; charset=UTF-8'
        body body_txt
      end
    end
    str=mail.to_s.gsub("multipart/alternative","multipart/mixed")
    encoded = Base64.encode64(str)
    AmazonSES::Base.make_request({"Action"=>"SendRawEmail", "RawMessage.Data"=>encoded},secret,key)
  end
end