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
12
13
14
15
16
17
18
19
20
# File 'lib/amazon_ses/amz_mail.rb', line 5

def self.send(source,to_addresses,subject,body,secret,key)
  if AmazonSES::StatObject.new(secret,key).reached_quota?
    raise "Sorry you have reached your quota."
  else
    begin
      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)
    rescue Exception=>e
      #puts "Error in AmazonSES::AmzMail.send"+e.to_s
      raise e.to_s
    end
  end
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.…



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/amazon_ses/amz_mail.rb', line 24

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
    begin
      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)
    rescue Exception=>e
      #puts "Errror in AmazonSES:AmzMail.send_html "+e.to_s
      raise e.to_s
    end
  end
end

.send_raw(mail_string, secret, key) ⇒ Object

will take a raw mail string encode it an send it.



48
49
50
51
52
53
54
55
# File 'lib/amazon_ses/amz_mail.rb', line 48

def self.send_raw(mail_string,secret,key)
  begin
    encoded = Base64.encode64(mail_string)
    AmazonSES::Base.make_request({"Action"=>"SendRawEmail", "RawMessage.Data"=>encoded},secret,key)
  rescue Exception=>e
    raise e.to_s
  end
end