Module: AWS::SES::SendEmail

Included in:
Base
Defined in:
lib/aws/ses/send_email.rb

Overview

Adds functionality for send_email and send_raw_email Use the following to send an e-mail:

ses = AWS::SES::Base.new( ... connection info ... )
ses.send_email :to        => ['[email protected]', '[email protected]'],
             :source    => '[email protected]',
             :subject   => 'Subject Line'
             :text_body => 'Internal text body'

You can also send Mail objects using send_raw_email:

m = Mail.new( :to => ..., :from => ... )
ses.send_raw_email(m)

send_raw_email will also take a hash and pass it through Mail.new automatically as well.

Instance Method Summary collapse

Instance Method Details

#send_email(options = {}) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/aws/ses/send_email.rb', line 45

def send_email(options = {})
  package     = {}
  
  package['Source'] = options[:source] || options[:from]
  
  add_array_to_hash!(package, 'Destination.ToAddresses', options[:to]) if options[:to]
  add_array_to_hash!(package, 'Destination.CcAddresses', options[:cc]) if options[:cc]
  add_array_to_hash!(package, 'Destination.BccAddresses', options[:bcc]) if options[:bcc]
  
  package['Message.Subject.Data'] = options[:subject]
  
  package['Message.Body.Html.Data'] = options[:html_body] if options[:html_body]
  package['Message.Body.Text.Data'] = options[:text_body] || options[:body] if options[:text_body] || options[:body]
  
  package['ReturnPath'] = options[:return_path] if options[:return_path]
  
  request('SendEmail', package)
end

#send_raw_email(mail) ⇒ Response Also known as: deliver!, deliver

Sends using the SendRawEmail method This gives the most control and flexibility

This uses the underlying Mail object from the mail gem You can pass in a Mail object, a Hash of params that will be parsed by Mail.new, or just a string

Note that the params are different from send_email Specifically, the following fields from send_email will NOT work:

  • :source

  • :html_body

  • :text_body

send_email accepts the aliases of :from & :body in order to be more compatible with the Mail gem

This method is aliased as deliver and deliver! for compatibility (especially with Rails)

Parameters:

  • mail (Hash)

    a customizable set of options

Options Hash (mail):

  • A (String)

    raw string that is a properly formatted e-mail message

  • A (Hash)

    hash that will be parsed by Mail.new

  • A (Mail)

    mail object, ready to be encoded

Returns:



85
86
87
88
89
# File 'lib/aws/ses/send_email.rb', line 85

def send_raw_email(mail)
  message = mail.is_a?(Hash) ? Mail.new(mail).to_s : mail.to_s
  package = { 'RawMessage.Data' => Base64::encode64(message) }
  request('SendRawEmail', package)
end