class Fog::AWS::SES::Real
Public Class Methods
Initialize connection to SES
Notes¶ ↑
options parameter must include values for :aws_access_key_id and :aws_secret_access_key in order to create a connection
Examples¶ ↑
ses = SES.new( :aws_access_key_id => your_aws_access_key_id, :aws_secret_access_key => your_aws_secret_access_key )
Parameters¶ ↑
-
options<~Hash> - config arguments for connection. Defaults to {}.
-
region<~String> - optional region to use. For instance, 'us-east-1' and etc.
-
Returns¶ ↑
# File lib/fog/aws/ses.rb, line 48 def initialize(options={}) @use_iam_profile = options[:use_iam_profile] setup_credentials(options) @instrumentor = options[:instrumentor] @instrumentor_name = options[:instrumentor_name] || 'fog.aws.ses' @connection_options = options[:connection_options] || {} options[:region] ||= 'us-east-1' @host = options[:host] || "email.#{options[:region]}.amazonaws.com" @path = options[:path] || '/' @persistent = options[:persistent] || false @port = options[:port] || 443 @scheme = options[:scheme] || 'https' @connection = Fog::XML::Connection.new("#{@scheme}://#{@host}:#{@port}#{@path}", @persistent, @connection_options) end
Public Instance Methods
Delete an existing verified email address
Parameters¶ ↑
-
email_address<~String> - Email Address to be removed
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'ResponseMetadata'<~Hash>:
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/delete_verified_email_address.rb, line 16 def delete_verified_email_address(email_address) request({ 'Action' => 'DeleteVerifiedEmailAddress', 'EmailAddress' => email_address, :parser => Fog::Parsers::AWS::SES::DeleteVerifiedEmailAddress.new }) end
Returns the user's current activity limits.
Parameters¶ ↑
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'GetSendQuotaResult'<~Hash>
-
'Max24HourSend' <~String>
-
'MaxSendRate' <~String>
-
'SentLast24Hours' <~String>
-
-
'ResponseMetadata'<~Hash>:
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/get_send_quota.rb, line 20 def get_send_quota request({ 'Action' => 'GetSendQuota', :parser => Fog::Parsers::AWS::SES::GetSendQuota.new }) end
Returns the user's current activity limits.
Parameters¶ ↑
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'GetSendStatisticsResult'<~Hash>
-
'SendDataPoints' <~Array>
-
'Bounces' <~String>
-
'Complaints' <~String>
-
'DeliveryAttempts' <~String>
-
'Rejects' <~String>
-
'Timestamp' <~String>
-
-
-
'ResponseMetadata'<~Hash>:
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/get_send_statistics.rb, line 23 def get_send_statistics request({ 'Action' => 'GetSendStatistics', :parser => Fog::Parsers::AWS::SES::GetSendStatistics.new }) end
Returns a list containing all of the email addresses that have been verified
Parameters¶ ↑
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'VerifiedEmailAddresses' <~Array>
-
'ResponseMetadata'<~Hash>:
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/list_verified_email_addresses.rb, line 17 def list_verified_email_addresses request({ 'Action' => 'ListVerifiedEmailAddresses', :parser => Fog::Parsers::AWS::SES::ListVerifiedEmailAddresses.new }) end
# File lib/fog/aws/ses.rb, line 65 def reload @connection.reset end
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.
-
ToAddresses <~Array> - The To: field(s) of the message.
-
-
Message <~Hash> - The message to be sent.
-
Body <~Hash>
-
Html <~Hash>
-
Charset <~String>
-
Data <~String>
-
-
Text <~Hash>
-
Charset <~String>
-
Data <~String>
-
-
-
Subject <~Hash>
-
Charset <~String>
-
Data <~String>
-
-
-
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>:
-
body<~Hash>:
-
'MessageId'<~String> - Id of message
-
'ResponseMetadata'<~Hash>:
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/send_email.rb, line 36 def send_email(source, destination, message, options = {}) params = { 'Source' => source } for key, values in destination params.merge!(Fog::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.key?('ReplyToAddresses') params.merge!(Fog::AWS.indexed_param("ReplyToAddresses.member", [*options['ReplyToAddresses']])) end if options.key?('ReturnPath') params['ReturnPath'] = options['ReturnPath'] end request({ 'Action' => 'SendEmail', :parser => Fog::Parsers::AWS::SES::SendEmail.new }.merge(params)) end
Send a raw email
Parameters¶ ↑
-
RawMessage <~String> - The message to be sent.
-
Options <~Hash>
-
Source <~String> - The sender's email address. Takes precenence over Return-Path if specified in RawMessage
-
Destinations <~Array> - All destinations for this email.
-
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'MessageId'<~String> - Id of message
-
'ResponseMetadata'<~Hash>:
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/send_raw_email.rb, line 21 def send_raw_email(raw_message, options = {}) params = {} if options.key?('Destinations') params.merge!(Fog::AWS.indexed_param('Destinations.member', [*options['Destinations']])) end if options.key?('Source') params['Source'] = options['Source'] end request({ 'Action' => 'SendRawEmail', 'RawMessage.Data' => Base64.encode64(raw_message.to_s).chomp!, :parser => Fog::Parsers::AWS::SES::SendRawEmail.new }.merge(params)) end
Verifies a domain. This action returns a verification authorization token which must be added as a DNS
TXT record to the domain.
Parameters¶ ↑
-
domain<~String> - The domain to be verified
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'ResponseMetadata'<~Hash>:
-
'VerificationToken'<~String> - Verification token
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/verify_domain_identity.rb, line 18 def verify_domain_identity(domain) request({ 'Action' => 'VerifyDomainIdentity', 'Domain' => domain, :parser => Fog::Parsers::AWS::SES::VerifyDomainIdentity.new }) end
Verifies an email address. This action causes a confirmation email message to be sent to the specified address.
Parameters¶ ↑
-
email_address<~String> - The email address to be verified
Returns¶ ↑
-
response<~Excon::Response>:
-
body<~Hash>:
-
'ResponseMetadata'<~Hash>:
-
'RequestId'<~String> - Id of request
-
-
-
# File lib/fog/aws/requests/ses/verify_email_address.rb, line 16 def verify_email_address(email_address) request({ 'Action' => 'VerifyEmailAddress', 'EmailAddress' => email_address, :parser => Fog::Parsers::AWS::SES::VerifyEmailAddress.new }) end
Private Instance Methods
# File lib/fog/aws/ses.rb, line 114 def _request(body, headers, idempotent, parser) @connection.request({ :body => body, :expects => 200, :headers => headers, :idempotent => idempotent, :host => @host, :method => 'POST', :parser => parser }) rescue Excon::Errors::HTTPStatusError => error match = Fog::AWS::Errors.match_error(error) raise if match.empty? raise case match[:code] when 'MessageRejected' Fog::AWS::SES::MessageRejected.slurp(error, match[:message]) when 'InvalidParameterValue' Fog::AWS::SES::InvalidParameterError.slurp(error, match[:message]) else Fog::AWS::SES::Error.slurp(error, "#{match[:code]} => #{match[:message]}") end end
# File lib/fog/aws/ses.rb, line 80 def request(params) refresh_credentials_if_expired idempotent = params.delete(:idempotent) parser = params.delete(:parser) headers = { 'Content-Type' => 'application/x-www-form-urlencoded', 'Date' => Fog::Time.now.to_date_header, } headers['x-amz-security-token'] = @aws_session_token if @aws_session_token #AWS3-HTTPS AWSAccessKeyId=<Your AWS Access Key ID>, Algorithm=HmacSHA256, Signature=<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 '&' if @instrumentor @instrumentor.instrument("#{@instrumentor_name}.request", params) do _request(body, headers, idempotent, parser) end else _request(body, headers, idempotent, parser) end end
# File lib/fog/aws/ses.rb, line 71 def setup_credentials(options) @aws_access_key_id = options[:aws_access_key_id] @aws_secret_access_key = options[:aws_secret_access_key] @aws_session_token = options[:aws_session_token] @aws_credentials_expire_at = options[:aws_credentials_expire_at] @hmac = Fog::HMAC.new('sha256', @aws_secret_access_key) end