o ckF[\@stddlZddlZddlmZmZddlmZddlmZddl m Z ddl Z ddl Z ddl mZGdddeZdS) N)sixurllib)AWSAuthConnection)BotoServerError) RegionInfo) exceptionscseZdZeZdZdZdZ     d5fdd Zd d Z d d Z d6fdd Z ddZ   d7ddZ d8ddZddZddZddZddZdd Zd!d"Zd#d$Zd%d&Zd'd(Zd)d*Zd+d,Zd-d.Zd/d0Zd6d1d2Zd9d3d4ZZS): SESConnectionz us-east-1zemail.us-east-1.amazonaws.comz 2010-12-01NTr/csP| s t||j|j} | |_tt|j|jj||||||||| | | | ||ddS)N)security_tokenvalidate_certs profile_name)rDefaultRegionNameDefaultRegionEndpointregionsuperr__init__endpoint)selfaws_access_key_idaws_secret_access_key is_secureportproxy proxy_port proxy_user proxy_passdebughttps_connection_factoryrpathr r r  __class__5/usr/lib/python3/dist-packages/boto/ses/connection.pyr)s zSESConnection.__init__cCsdgS)Nsesr!rr!r!r"_required_auth_capability;sz'SESConnection._required_auth_capabilitycCsFt|tjr |g}tdt|dD]}||d|d||f<qdS)a-Add an AWS API-compatible parameter list to a dictionary. :type params: dict :param params: The parameter dictionary :type items: list :param items: Items to be included in the list :type label: string :param label: The parameter list's name z%s.%dN) isinstancer string_typesrangelen)rparamsitemslabelir!r!r"_build_list_params>s z SESConnection._build_list_paramsc sd}d|i}|p i}||d<|D]\}}t|tjr#|d||<qtt|jdd|tj |d}| d}|j dkrZd } d } tjj| | d } tj| d } | || S|||d S) zMake a call to the SES API. :type action: string :param action: The API method to use (e.g. SendRawEmail) :type params: dict :param params: Parameters that will be sent as POST data with the API call. z0application/x-www-form-urlencoded; charset=UTF-8z Content-TypeActionutf-8POSTr )headersdata)VerifiedEmailAddresses Identities DkimTokensDkimAttributesVerificationAttributesSendDataPoints)memberitementry) list_marker item_markerN)r,r'r text_typeencoderr make_requestrparse urlencodereaddecodestatusboto jsonresponseElement XmlHandler _handle_error) ractionr+ctr3kvresponsebody list_markers item_markersehrr!r" _make_requestOs2      zSESConnection._make_requestcCstjd|j|jftjd|d|vrtj}d}nXd|vr(tj}d}nNd|vr2tj}d}nDd|vr| | d<|d vrFtd | sN| sNtd || |d |r^|| |d |rg|| |d|rp|| |d|d| S)aComposes an email message based on input data, and then immediately queues the message for sending. :type source: string :param source: The sender's email address. :type subject: string :param subject: The subject of the message: A short summary of the content, which will appear in the recipient's inbox. :type body: string :param body: The message body. :type to_addresses: list of strings or string :param to_addresses: The To: field(s) of the message. :type cc_addresses: list of strings or string :param cc_addresses: The CC: field(s) of the message. :type bcc_addresses: list of strings or string :param bcc_addresses: The BCC: field(s) of the message. :type format: string :param format: The format of the message's body, must be either "text" or "html". :type reply_addresses: list of strings or string :param reply_addresses: The reply-to email address(es) for the message. If the recipient replies to the message, each reply-to address will receive the reply. :type return_path: string :param return_path: 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. :type text_body: string :param text_body: The text body to send with this email. :type html_body: string :param html_body: The html body to send with this email. NrkzMYou've passed in both a body and a text_body; please choose one or the other.zNYou've passed in both a body and an html_body; please choose one or the other.)SourcezMessage.Subject.Data ReturnPathzMessage.Body.Html.DatazMessage.Body.Text.Data)rkhtmlz*'format' argument must be 'text' or 'html'z#No text or html body found for mailzDestination.ToAddresses.memberzDestination.CcAddresses.memberzDestination.BccAddresses.memberzReplyToAddresses.member SendEmail)lowerstripWarning ValueErrorr/rX) rsourcesubjectrS to_addresses cc_addresses bcc_addressesformatreply_addresses return_path text_body html_bodyr+r!r!r" send_emailsL 3 zSESConnection.send_emailcCsNt|tjr |d}dt|i}|r||d<|r!|||d|d|S)atSends an email message, with header and content specified by the client. The SendRawEmail action is useful for sending multipart MIME emails, with attachments or inline content. The raw text of the message must comply with Internet email standards; otherwise, the message cannot be sent. :type source: string :param source: The sender's email address. Amazon's docs say: If you specify the Source parameter, then bounce notifications and complaints will be sent to this email address. This takes precedence over any Return-Path header that you might include in the raw text of the message. :type raw_message: string :param raw_message: The raw text of the message. The client is responsible for ensuring the following: - Message must contain a header and a body, separated by a blank line. - All required header fields must be present. - Each part of a multipart MIME message must be formatted properly. - MIME content types must be among those supported by Amazon SES. Refer to the Amazon SES Developer Guide for more details. - Content must be base64-encoded, if MIME requires it. :type destinations: list of strings or string :param destinations: A list of destinations for the message. r1zRawMessage.DatarlzDestinations.member SendRawEmail)r'rrArBbase64 b64encoder/rX)r raw_messagert destinationsr+r!r!r"send_raw_emails    zSESConnection.send_raw_emailcC |dS)zFetch a list of the email addresses that have been verified. :rtype: dict :returns: A ListVerifiedEmailAddressesResponse structure. Note that keys must be unicode strings. ListVerifiedEmailAddressesrXr$r!r!r"list_verified_email_addressesE z+SESConnection.list_verified_email_addressescCr)zFetches the user's current activity limits. :rtype: dict :returns: A GetSendQuotaResponse structure. Note that keys must be unicode strings. GetSendQuotarr$r!r!r"get_send_quotaNrzSESConnection.get_send_quotacCr)auFetches the user's sending statistics. The result is a list of data points, representing the last two weeks of sending activity. Each data point in the list contains statistics for a 15-minute interval. :rtype: dict :returns: A GetSendStatisticsResponse structure. Note that keys must be unicode strings. GetSendStatisticsrr$r!r!r"get_send_statisticsWs z!SESConnection.get_send_statisticscC|dd|iS)aDeletes the specified email address from the list of verified addresses. :type email_adddress: string :param email_address: The email address to be removed from the list of verified addreses. :rtype: dict :returns: A DeleteVerifiedEmailAddressResponse structure. Note that keys must be unicode strings. DeleteVerifiedEmailAddress EmailAddressrr email_addressr!r!r"delete_verified_email_addressds z+SESConnection.delete_verified_email_addresscCr)apVerifies an email address. This action causes a confirmation email message to be sent to the specified address. :type email_adddress: string :param email_address: The email address to be verified. :rtype: dict :returns: A VerifyEmailAddressResponse structure. Note that keys must be unicode strings. VerifyEmailAddressrrrr!r!r"verify_email_addresst z"SESConnection.verify_email_addresscCr)a Returns a set of DNS records, or tokens, that must be published in the domain name's DNS to complete the DKIM verification process. These tokens are DNS ``CNAME`` records that point to DKIM public keys hosted by Amazon SES. To complete the DKIM verification process, these tokens must be published in the domain's DNS. The tokens must remain published in order for Easy DKIM signing to function correctly. After the tokens are added to the domain's DNS, Amazon SES will be able to DKIM-sign email originating from that domain. To enable or disable Easy DKIM signing for a domain, use the ``SetIdentityDkimEnabled`` action. For more information about Easy DKIM, go to the `Amazon SES Developer Guide `_. :type domain: string :param domain: The domain name. VerifyDomainDkimDomainrrdomainr!r!r"verify_domain_dkimsz SESConnection.verify_domain_dkimcC |d||r ddSddS)aEnables or disables DKIM signing of email sent from an identity. * If Easy DKIM signing is enabled for a domain name identity (e.g., * ``example.com``), then Amazon SES will DKIM-sign all email sent by addresses under that domain name (e.g., ``user@example.com``) * If Easy DKIM signing is enabled for an email address, then Amazon SES will DKIM-sign all email sent by that email address. For email addresses (e.g., ``user@example.com``), you can only enable Easy DKIM signing if the corresponding domain (e.g., ``example.com``) has been set up for Easy DKIM using the AWS Console or the ``VerifyDomainDkim`` action. :type identity: string :param identity: An email address or domain name. :type dkim_enabled: bool :param dkim_enabled: Specifies whether or not to enable DKIM signing. SetIdentityDkimEnabledtruefalse)Identity DkimEnabledr)ridentity dkim_enabledr!r!r"set_identity_dkim_enableds z'SESConnection.set_identity_dkim_enabledcCi}|||d|d|S)afGet attributes associated with a list of verified identities. Given a list of verified identities (email addresses and/or domains), returns a structure describing identity notification attributes. :type identities: list :param identities: A list of verified identities (email addresses and/or domains). Identities.memberGetIdentityDkimAttributesr/rXr identitiesr+r!r!r"get_identity_dkim_attributess  z*SESConnection.get_identity_dkim_attributescCr)a+Returns a list containing all of the identities (email addresses and domains) for a specific AWS Account, regardless of verification status. :rtype: dict :returns: A ListIdentitiesResponse structure. Note that keys must be unicode strings. ListIdentitiesrr$r!r!r"list_identitiess zSESConnection.list_identitiescCr)aGiven a list of identities (email addresses and/or domains), returns the verification status and (for domain identities) the verification token for each identity. :type identities: list of strings or string :param identities: List of identities. :rtype: dict :returns: A GetIdentityVerificationAttributesResponse structure. Note that keys must be unicode strings. r!GetIdentityVerificationAttributesrrr!r!r"$get_identity_verification_attributess   z2SESConnection.get_identity_verification_attributescCr)zVerifies a domain. :type domain: string :param domain: The domain to be verified. :rtype: dict :returns: A VerifyDomainIdentityResponse structure. Note that keys must be unicode strings. VerifyDomainIdentityrrrr!r!r"verify_domain_identitys z$SESConnection.verify_domain_identitycCr)aqVerifies an email address. This action causes a confirmation email message to be sent to the specified address. :type email_adddress: string :param email_address: The email address to be verified. :rtype: dict :returns: A VerifyEmailIdentityResponse structure. Note that keys must be unicode strings. VerifyEmailIdentityrrrr!r!r"verify_email_identityrz#SESConnection.verify_email_identitycCr)aJDeletes the specified identity (email address or domain) from the list of verified identities. :type identity: string :param identity: The identity to be deleted. :rtype: dict :returns: A DeleteIdentityResponse structure. Note that keys must be unicode strings. DeleteIdentityrr)rrr!r!r"delete_identityrzSESConnection.delete_identitycCs"||d}|r ||d<|d|S)aSets an SNS topic to publish bounce or complaint notifications for emails sent with the given identity as the Source. Publishing to topics may only be disabled when feedback forwarding is enabled. :type identity: string :param identity: An email address or domain name. :type notification_type: string :param notification_type: The type of feedback notifications that will be published to the specified topic. Valid Values: Bounce | Complaint | Delivery :type sns_topic: string or None :param sns_topic: The Amazon Resource Name (ARN) of the Amazon Simple Notification Service (Amazon SNS) topic. )rNotificationTypeSnsTopicSetIdentityNotificationTopicr)rrnotification_type sns_topicr+r!r!r"set_identity_notification_topic s  z-SESConnection.set_identity_notification_topiccCr)a Enables or disables SES feedback notification via email. Feedback forwarding may only be disabled when both complaint and bounce topics are set. :type identity: string :param identity: An email address or domain name. :type forwarding_enabled: bool :param forwarding_enabled: Specifies whether or not to enable feedback forwarding. $SetIdentityFeedbackForwardingEnabledrr)rForwardingEnabledr)rrforwarding_enabledr!r!r"(set_identity_feedback_forwarding_enabled&s  z6SESConnection.set_identity_feedback_forwarding_enabled)NNTNNNNNrNNr NTN)N)NNrkNNNN)NN)T)__name__ __module__ __qualname__rrhr r APIVersionrr%r/rXrMr~rrrrrrrrrrrrrrrr __classcell__r!r!rr"r"sF*; c/     r)rdr boto.compatrrboto.connectionrboto.exceptionrboto.regioninforrIboto.jsonresponseboto.sesrr\rr!r!r!r"s