HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/buyercall/buyercall/lib/__pycache__/util_boto3_ses.cpython-310.pyc
o

weK�@svddlZddlmZddlmZddlmZddlmZddl	Z	ddl
mZe�e
�ZGdd�d�ZGd	d
�d
�ZdS)�N)�encoders)�MIMEBase)�
MIMEMultipart)�MIMEText)�ClientErrorc@s�eZdZdZddgZdd�Zdd�Zd1d
d�Zdd
�Zddgfde	de
de	de	de	de
defdd�Zd2dd�Z
dd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Z		(d3d)d*�Zd+d,�Zd-d.�Zd/d0�ZdS)4�AmazonSimpleEmailServiceN�deb�shcCs
d|_dS)N)�default_sender)�self�r�>/home/arjun/projects/buyercall/buyercall/lib/util_boto3_ses.py�__init__s
z!AmazonSimpleEmailService.__init__cCsFtjd|j�dd�|j�dd�|j�dd�d�|_|j�dd�|_dS)N�ses�SES_REGION_NAME��AMAZON_ACCESS_KEY�AMAZON_SECRET_KEY��region_name�aws_access_key_id�aws_secret_access_key�SES_EMAIL_SOURCE)�boto3�client�config�get�
ses_clientr
)r�apprrr
�init_apps�z!AmazonSimpleEmailService.init_appr�New mailc	
Cs�z-|s|j}t|t�s|g}|jj|d|id|id|id|id�d�|d�}td|�|WStyE}ztd|�WYd}~dSd}~ww)	N�ToAddresses�Data��Text�Html��Subject�Body)�Source�Destination�Message�ConfigurationSetNamezresp : �Error : F)r
�
isinstance�listr�
send_email�print�	Exception)	r�
recipients�config_set_name�sender�subject�text�html�resp�errr
r0s,
���

��z#AmazonSimpleEmailService.send_emailc
Csjz|s|j}t|t�s|g}|jj||d|i|d�}|WSty4}zt|�iWYd}~Sd}~ww)Nr")r)�Destinations�
RawMessager,)r
r.r/r�send_raw_emailr2r1)rr5r3�
config_set�content�responser:rrr
�
send_raw_mail7s$
����z&AmazonSimpleEmailService.send_raw_mailr5r3�titler7r8�attachments�returnc
Cs|r|rdnd}t|�}||d<||d<d�|�|d<|r't|d�}	|�|	�|r3t|d�}	|�|	�|r�|D]H}
z/|
j�d	�d
}||jvrgtdd�}	|	�|
�	��t
�|	�|	�d
d�
|
j��|�|	�Wq7ty}ztd|�WYd}~q7d}~ww|S)a�
        Creates a MIME multipart message object.
        Uses only the Python `email` standard library.
        Emails, both sender and recipients, can be just the email string or have the format 'The Name <the_email@host.com>'.
        :param sender: The sender.
        :param recipients: List of recipients. Needs to be a list, even if only one recipient.
        :param title: The title of the email.
        :param text: The text version of the email body (optional).
        :param html: The html version of the email body (optional).
        :param attachments: List of files to attach in the email.
        :return: A `MIMEMultipart` to be used to send the email.
        �alternative�mixedr'�Fromz, �To�plainr8�.����applicationzoctet-streamzContent-Dispositionzattachment; filename="{}"zError: N)r�joinr�attach�filename�split�exclude_file_typesr�set_payload�readr�
encode_base64�
add_header�formatr2r1)
rr5r3rBr7r8rC�multipart_content_subtype�msg�part�
attachment�	extensionr:rrr
�create_multipart_messageLs6







���z1AmazonSimpleEmailService.create_multipart_messageTc
Cs�ddid�}z>|r6|jj|d�}d|vr||dd<|r0|jj|d�}d|vr3||dd	<W|SW|SW|Sd
|d<d|d
<i|d<W|Sty[}zd
|d<WYd}~|Sd}~ww)z�Verify a domain
        Args:
            domain (str): Domain to verify
            is_dkim (bool, optional): Need DKIM enabled. Defaults to False.
        Returns:
            dict: On success, it will return dkim response
        T�Success��status�message�data)�Domain�VerificationTokenra�domain_identity�
DkimTokens�domain_dkimFr_zInvalid domainr`N)r�verify_domain_identity�verify_domain_dkimr2)r�domain�is_dkimr@�id_response�
dkim_response�exrrr
�
verify_domainus8��
���
���z&AmazonSimpleEmailService.verify_domainc
Cs�ddd�}z&|r!|jj|d�}d|vrd|d<d|d	<W|SW|Sd|d<d
|d	<W|StyH}zd|d<t|�|d	<WYd}~|Sd}~ww)NTr]�r_r`)�EmailAddress�ResponseMetadataFr_�	API errorr`�
Invalid email)r�verify_email_identityr2�str)r�emailr@�ve_responsermrrr
rt�s*
�
�
�
���z.AmazonSimpleEmailService.verify_email_identityc
Cs�ddgd�}z%|r!t|t�s|g}|jj|d�}|pg|d<W|Sd|d<d|d	<W|StyH}zd|d<t|�|d	<WYd
}~|Sd
}~ww)z�Check the status of the identities that are previously added/
        Args:
            identities (list): idnetites list
        Returns:
            dict: identities if verified
        Tr]r^��
IdentitiesraFr_�Invalid domain/emailr`N)r.r/r�$get_identity_verification_attributesr2ru)r�
identitiesr@�added_identitiesrmrrr
�check_identity_verify_status�s&
�	�
���z5AmazonSimpleEmailService.check_identity_verify_statusc
Cs�ddid�}z|r|jjd|id�}||d<W|Sd|d<d	|d
<W|Sty@}zd|d<t|�|d
<WYd}~|Sd}~ww)a�Creates a configuration set.

        Args:
            name (str): The name of the configuration set.
                        Name requirements:
                        Contain only letters (a-z, A-Z), numbers (0-9), underscores (_), or dashes (-).
                        Contain 64 characters or fewer.
        Returns:
            dict: Returns a dict contains name of the configuration set that created.
        Tr]r^�Name)�ConfigurationSetraFr_zInvalid configuration namer`N)r�create_configuration_setr2ru)r�namer@�config_set_responsermrrr
r��s$��
	�
���z1AmazonSimpleEmailService.create_configuration_setc
C�ddid�}z|r|r|jj||d�}||d<W|Sd|d<d|d	<W|StyA}zd|d<t|�|d	<WYd
}~|Sd
}~ww)a5Creates a configuration set event destination.

        Args:
            configset_name (str): Coonfiguration set name
            destination (dict, optional): Destination configuration details.
        Returns:
            dict: Returns a dict contains name of the configuration set that created.

        Tr]r^)r,�EventDestinationraFr_�*Invalid configuration name and destinationr`N)r�*create_configuration_set_event_destinationr2ru)r�configset_name�destinationr@�config_set_evt_dest_responsermrrr
�create_event_destination��$
�
	�
���z1AmazonSimpleEmailService.create_event_destinationc
Cr�)aCreates an association between a configuration set and a custom domain for open and click event tracking.

        Args:
            configset_name (str): The name of the configuration set that the tracking options should be associated with.
            tracking_options (dict, optional): contains CustomRedirectDomain. A custom subdomain that will be used to redirect email
            recipients to the Amazon SES event tracking domain.
        Returns:
            dict: Returns a dict contains success or failiure
        Tr]r^)r,�TrackingOptionsraFr_r�r`N)r�)create_configuration_set_tracking_optionsr2ru)rr��tracking_optionsr@�config_set_tracking_responsermrrr
�create_tracking_options�r�z0AmazonSimpleEmailService.create_tracking_optionsc
Cstddid�}z|rdnd}|jj|||d�d�d�WdSty9}zd	|d
<t|�|d<WYd}~dSd}~ww)
a�
        Creates a filter that allows or blocks incoming mail from an IP address or
        range.
        Args:
            filter_name(str): The name to give the filter.
            ip_address_or_range(str): The IP address or range to block or allow.
            allow(bool): When True, incoming mail is allowed from the specified IP
                        address or range; otherwise, it is blocked.
        Returns:
            dict: Returns a dict contains success or failiure
        Tr]r^�Allow�Block)�Cidr�Policy)r�IpFilter)�FilterFr_r`N)r�create_receipt_filterrru)r�filter_name�ip_address_or_range�allowr@�policyrmrrr
r�s�����z.AmazonSimpleEmailService.create_receipt_filterc
Cs~ddid�}z|r|jj|d�}||d<W|Sd|d<d|d	<W|Sty>}zd|d<t|�|d	<WYd
}~|Sd
}~ww)z�Creates an empty receipt rule set.
        Args:
            name (str): The name of the rule set to create
        Returns:
            dict: Returns a dict contains success or failure
        Tr]r^)�RuleSetNameraFr_�Invalid inputsr`N)r�create_receipt_rule_setr2ru)rr�r@�ruleset_resprmrrr
r�4s"�
	�
���z0AmazonSimpleEmailService.create_receipt_rule_set�emails/c
Cs�|durg}ddid�}z5|r7|r7|r7d|||d�igd|ddd�}|r(||d	<|jj||d
�}	|	|d<W|Sd|d
<d|d<W|Sty^}
zd|d
<t|
�|d<WYd}
~
|Sd}
~
ww)aRCreates a receipt rule.
        Args:
            param topic_arn (str):  The Amazon Resource Name (ARN) of the Amazon SNS topic to notify.
            param rule_name (str): The name of the receipt rule.
            param bucket_name: S3 bucket name
        Returns:
            dict: Returns a dict contains success or failure

        NTr]r^�S3Action)�TopicArn�
BucketName�ObjectKeyPrefix�Optional)�Actions�Enabledr�ScanEnabled�	TlsPolicy�
Recipients)r��RuleraFr_r�r`)r�create_receipt_ruler2ru)r�
rule_set_name�	topic_arn�	rule_name�bucket_namer3�
key_prefixr@�rule�receipt_resprmrrr
r�LsD���	��
	�
���z,AmazonSimpleEmailService.create_receipt_rulec
Csrddgd�}z|j��}|d|d<W|Sty8}zt�t|��d|d<t|�|d<WYd}~|Sd}~ww)	NTr]r^ryraFr_r`�r�list_identitiesr2�log�errorru�rr@r|rmrrr
�list_all_identities~s
���z,AmazonSimpleEmailService.list_all_identitiesc
C�vddgd�}z|jjdd�}|d|d<W|Sty:}zt�t|��d|d	<t|�|d
<WYd}~|Sd}~ww)NTr]r^rp��IdentityTyperyraFr_r`r�r�rrr
�list_email_identities�����z.AmazonSimpleEmailService.list_email_identitiesc
Cr�)NTr]r^rbr�ryraFr_r`r�r�rrr
�list_domain_identities�r�z/AmazonSimpleEmailService.list_domain_identities)rNr rr)T)Nr�)�__name__�
__module__�__qualname__rrQrrr0rArur/rr\rnrtr~r�r�r�r�r�r�r�r�r�rrrr
r
sL
	�������
�
)"
�2

rc@s2eZdZdZdd�Zdd�Zddd	�Zd
d�ZdS)
�AmazonSimpleEmailServiceV2NcCs.tjd|d|d|dd�|_|d|_dS)N�sesv2rrrrr)rrrr
)r�
ses_configrrr
r�s�z#AmazonSimpleEmailServiceV2.__init__c
Cs�ddid�}z|r|jj|d�}||d<W|Sd|d<d|d	<W|StyE}zt�t|��d|d<t|�|d	<WYd
}~|Sd
}~ww)z�Get the email identity that already added.
        Args:
            identity (str): A domain or email address
        Returns:
            dict: Success or failed response
        Tr]r^rxraFr_rzr`N)r�get_email_identityr2r�r�ru)r�identityr@�added_identityrmrrr
r��s$�

�
���z-AmazonSimpleEmailServiceV2.get_email_identity�	Test mailrc	
Cs�z2|s|j}t|t�s|g}|jj|d|id|dd�|dd�|dd�d�d�i|d�}|r0dWSd	WStyO}zt�d
t|����WYd}~d	Sd}~ww)Nr!�SimplezUTF-8)r"�Charsetr#r&)�FromEmailAddressr*�Contentr,TFr-)	r
r.r/rr0r2r�r�ru)	rr3r5�config_namer6r7r8r9r:rrr
r0�s:
���������z%AmazonSimpleEmailServiceV2.send_emailc
Cs�ddd�}z+|r&|jj||d�}t|�d|vr#d|d<d|d	<W|SW|Sd|d<d
|d	<W|StyT}zt�t|��d|d<t|�|d	<WYd}~|Sd}~ww)z�Verify an email or domain
        Args:
            identity (str): Email or domain to verify
            config_set (str): Configuration name to create
        Returns:
            dict: Success or failed response
        Tr]ro)�
EmailIdentityr,rqFr_rrr`rsN)r�create_email_identityr1r2r�r�ru)rr�r>r@rwrmrrr
�verify_identity�s0
�
	��
���z*AmazonSimpleEmailServiceV2.verify_identity)NNr�rr)r�r�r�rrr�r0r�rrrr
r��s	
$r�)�loggingrvr�email.mime.baser�email.mime.multipartr�email.mime.textrr�botocore.exceptionsr�	getLoggerr�r�rr�rrrr
�<module>s