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 => '"Steve Smith" <[email protected]>',
:subject => 'Subject Line'
:text_body => 'Internal text body'
By default, the email “from” display address is whatever is before the @. To change the display from, use the format:
"Steve Smith" <[email protected]>
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
- #send_email(options = {}) ⇒ Object
-
#send_raw_email(mail, args = {}) ⇒ Response
(also: #deliver!, #deliver)
Sends using the SendRawEmail method This gives the most control and flexibility.
Instance Method Details
#send_email(options = {}) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/aws/ses/send_email.rb', line 52 def send_email( = {}) package = {} package['Source'] = [:source] || [:from] add_array_to_hash!(package, 'Destination.ToAddresses', [:to]) if [:to] add_array_to_hash!(package, 'Destination.CcAddresses', [:cc]) if [:cc] add_array_to_hash!(package, 'Destination.BccAddresses', [:bcc]) if [:bcc] package['Message.Subject.Data'] = [:subject] package['Message.Body.Html.Data'] = [:html_body] if [:html_body] package['Message.Body.Text.Data'] = [:text_body] || [:body] if [:text_body] || [:body] package['ReturnPath'] = [:return_path] if [:return_path] add_array_to_hash!(package, 'ReplyToAddresses', [:reply_to]) if [:reply_to] request('SendEmail', package) end |
#send_raw_email(mail, args = {}) ⇒ 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)
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/aws/ses/send_email.rb', line 98 def send_raw_email(mail, args = {}) = (mail) package = { 'RawMessage.Data' => Base64::encode64() } package['Source'] = args[:from] if args[:from] package['Source'] = args[:source] if args[:source] if args[:destinations] add_array_to_hash!(package, 'Destinations', args[:destinations]) else add_array_to_hash!(package, 'Destinations', args[:to]) if args[:to] end request('SendRawEmail', package) end |