diff --git a/lib/fog/aws/requests/ses/delete_verified_email_address.rb b/lib/fog/aws/requests/ses/delete_verified_email_address.rb index 1be09f725..262165865 100644 --- a/lib/fog/aws/requests/ses/delete_verified_email_address.rb +++ b/lib/fog/aws/requests/ses/delete_verified_email_address.rb @@ -3,7 +3,7 @@ module Fog class SES class Real - require 'fog/aws/parsers/ses/delete_verified_email' + require 'fog/aws/parsers/ses/delete_verified_email_address' # Delete an existing verified email address # diff --git a/lib/fog/aws/requests/ses/send_email.rb b/lib/fog/aws/requests/ses/send_email.rb index a1e5c0bb8..e595c73a3 100644 --- a/lib/fog/aws/requests/ses/send_email.rb +++ b/lib/fog/aws/requests/ses/send_email.rb @@ -5,9 +5,10 @@ module Fog require 'fog/aws/parsers/ses/send_email' - # Delete an existing verified email address + # Send an email # # ==== Parameters + # * Source <~String> - The sender's email address # * Destination <~Hash> - The destination for this email, composed of To:, From:, and CC: fields. # * BccAddresses <~Array> - The BCC: field(s) of the message. # * CcAddresses <~Array> - The CC: field(s) of the message. @@ -23,9 +24,9 @@ module Fog # * Subject <~Hash> # * Charset <~String> # * Data <~String> - # * ReplyToAddresses <~Array> - The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply. - # * ReturnPath <~String> - The email address to which bounce notifications are to be forwarded. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter. - # * Source <~String> - The sender's email address + # * options <~Hash>: + # * ReplyToAddresses <~Array> - The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply. + # * ReturnPath <~String> - The email address to which bounce notifications are to be forwarded. If the message cannot be delivered to the recipient, then an error message will be returned from the recipient's ISP; this message will then be forwarded to the email address specified by the ReturnPath parameter. # # ==== Returns # * response<~Excon::Response>: @@ -33,13 +34,36 @@ module Fog # * 'DeleteVerfiedEmailAddressResponse'<~nil> # * 'ResponseMetadata'<~Hash>: # * 'RequestId'<~String> - Id of request - def send_email() - params = AWS.indexed_param('ReplyToAddresses.member', [*reply_to_addresses]) + def send_email(source, destination, message, options = {}) + params = { + 'Source' => source + } + + for key, values in destination + params.merge!(AWS.indexed_param("Destination.#{key}.member", [*values])) + end + + for key, value in message['Subject'] + params["Message.Subject.#{key}"] = value + end + + for type, data in message['Body'] + for key, value in data + params["Message.Body.#{type}.#{key}"] = value + end + end + + if options.has_key?('ReplyToAddresses') + params.merge!(AWS.indexed_param("ReplyToAddresses.member", [*options['ReplyToAddresses']])) + end + + if options.has_key?('ReturnPath') + params['ReturnPath'] = options['ReturnPath'] + end request({ - 'Action' => 'DeleteVerifiedEmailAddress', - 'EmailAddress' => email_address, - :parser => Fog::Parsers::AWS::SES::DeleteVerifiedEmailAddress.new + 'Action' => 'SendEmail', + :parser => Fog::Parsers::AWS::SES::SendEmail.new }.merge(params)) end @@ -47,7 +71,7 @@ module Fog class Mock - def delete_verified_email_address(email_address) + def send_email(source, destination, message, options = {}) Fog::Mock.not_implemented end diff --git a/lib/fog/aws/requests/ses/send_raw_email.rb b/lib/fog/aws/requests/ses/send_raw_email.rb index 1373163e9..11e4d8a9d 100644 --- a/lib/fog/aws/requests/ses/send_raw_email.rb +++ b/lib/fog/aws/requests/ses/send_raw_email.rb @@ -8,10 +8,10 @@ module Fog # Delete an existing verified email address # # ==== Parameters - # * Destinations <~Array> - The destination for this email, composed of To:, From:, and CC: fields. - # * RawMessage <~Hash> - The message to be sent. - # * Data <~String> - # * Source <~String> - The sender's email address + # * RawMessage <~String> - The message to be sent. + # * Options <~Hash> + # * Source <~String> - The sender's email address + # * Destinations <~Array> - The destination for this email, composed of To:, From:, and CC: fields. # # ==== Returns # * response<~Excon::Response>: @@ -19,13 +19,19 @@ module Fog # * 'DeleteVerfiedEmailAddressResponse'<~nil> # * 'ResponseMetadata'<~Hash>: # * 'RequestId'<~String> - Id of request - def send_raw_email() - # TODO: Make this work - params = AWS.indexed_param('ReplyToAddresses.member', [*reply_to_addresses]) + def send_raw_email(raw_message, options = {}) + params = {} + if options.has_key?('Destinations') + params['Destinations'] = AWS.indexed_param('Destinations.member', [*options['Destinations']]) + end + if options.has_key?('Source') + params['Source'] = options['Source'] + end request({ - 'Action' => 'SendRawEmail', - :parser => Fog::Parsers::AWS::SES::SendRawEmail.new + 'Action' => 'SendRawEmail', + 'RawMessage.Data' => Base64.encode64(raw_message).chomp!, + :parser => Fog::Parsers::AWS::SES::SendRawEmail.new }.merge(params)) end @@ -33,7 +39,7 @@ module Fog class Mock - def send_raw_email() + def send_raw_email(source, destinations, raw_message) Fog::Mock.not_implemented end diff --git a/lib/fog/aws/ses.rb b/lib/fog/aws/ses.rb index 4c779a03b..a63e97947 100644 --- a/lib/fog/aws/ses.rb +++ b/lib/fog/aws/ses.rb @@ -68,22 +68,29 @@ module Fog idempotent = params.delete(:idempotent) parser = params.delete(:parser) - body = AWS.signed_params( - params, - { - :aws_access_key_id => @aws_access_key_id, - :hmac => @hmac, - :host => @host, - :path => @path, - :port => @port, - :version => '2009-11-25' - } - ) + headers = { + 'Content-Type' => 'application/x-www-form-urlencoded', + 'Date' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000") + } + + #AWS3-HTTPS AWSAccessKeyId=, Algorithm=HmacSHA256, Signature= + headers['X-Amzn-Authorization'] = 'AWS3-HTTPS ' + headers['X-Amzn-Authorization'] << 'AWSAccessKeyId=' << @aws_access_key_id + headers['X-Amzn-Authorization'] << ', Algorithm=HmacSHA256' + headers['X-Amzn-Authorization'] << ', Signature=' << Base64.encode64(@hmac.sign(headers['Date'])).chomp! + + body = '' + for key in params.keys.sort + unless (value = params[key]).nil? + body << "#{key}=#{CGI.escape(value.to_s).gsub(/\+/, '%20')}&" + end + end + body.chop! # remove trailing '&' response = @connection.request({ :body => body, :expects => 200, - :headers => { 'Content-Type' => 'application/x-www-form-urlencoded' }, + :headers => headers, :idempotent => idempotent, :host => @host, :method => 'POST', diff --git a/lib/fog/bin/aws.rb b/lib/fog/bin/aws.rb index 3a9424d39..1060c670e 100644 --- a/lib/fog/bin/aws.rb +++ b/lib/fog/bin/aws.rb @@ -15,6 +15,8 @@ class AWS < Fog::Bin Fog::AWS::IAM when :sdb Fog::AWS::SimpleDB + when :ses + Fog::AWS::SES when :eu_storage, :s3, :storage Fog::AWS::Storage else @@ -48,6 +50,8 @@ class AWS < Fog::Bin Fog::Storage.new(:provider => 'AWS', :region => 'eu-west-1') when :sdb Fog::AWS::SimpleDB.new + when :ses + Fog::AWS::SES.new when :s3 location = caller.first warning = "[yellow][WARN] AWS[:s3] is deprecated, use AWS[:storage] instead[/]" @@ -64,7 +68,7 @@ class AWS < Fog::Bin end def services - [:cdn, :compute, :dns, :elb, :iam, :sdb, :storage] + [:cdn, :compute, :dns, :elb, :iam, :sdb, :ses, :storage] end end diff --git a/lib/fog/providers/aws.rb b/lib/fog/providers/aws.rb index dcf6e0251..71e3594d0 100644 --- a/lib/fog/providers/aws.rb +++ b/lib/fog/providers/aws.rb @@ -15,6 +15,7 @@ module Fog service(:elb, 'aws/elb') service(:iam, 'aws/iam') service(:s3, 'storage/aws') + service(:ses, 'aws/ses') service(:simpledb, 'aws/simpledb') service(:storage, 'storage/aws')