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_ses_email.cpython-310.pyc
o

�we��@s�ddlZddlmZddlmZddlmZddlmZddl	m
Z
ddlmZddl
mZdd	lmZddd�Z	
	dd
d�ZGdd�de�ZdS)�N)�SMTPHandler)�ClientError)�current_app)�Partnership)�MIMEApplication)�
MIMEMultipart)�MIMEText)�datetime�c
Cs@tjdtjdtjdtjdd�}|s>tjd}d|d}tj�tj|k���}	|	dur=|	j	r=|	j	}|	j
d	|d}n|}|rL|d
d|d}z+|rc|j|d|id
|idd
|iid�d�}
n|j|d|id
|idd
|iid�d�}
Wnty�}zt
|jdd�WYd}~dSd}~wwt
d�||
d��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�BuyerCall <�>� <� �<�ToAddresses�Data�Text��Subject�Body��Source�Destination�Message�Html�Errorr"�#Email sent using {}! Message ID: {}�	MessageId)�boto3�clientr�configr�query�filter�id�first�email_sender�name�
send_emailr�print�response�format)�
recipients�p_id�subject�text�html�sender�account_namer�sender_email�partnerr2�e�r>�>/home/arjun/projects/buyercall/buyercall/lib/util_ses_email.py�send_ses_emailsT�
��������
 ��r@c
Cs�tjdtjdtjdtjdd�}|s>tjd}	d|	d}tj�tj|k���}
|
dur=|
j	r=|
j	}	|
j
d	|	d}n|}	|rL|d
d|	d}|rR|rRdnd
}t|�}||d<||d<||d<|rqt|d�}
|�
|
�n
t|d�}
|�
|
�|}t|d��!}t|���}|jdd|dtt���d��d�Wd�n1s�wY|�
|�z|j||d|��id�}td�|	|d��WdSty�}zt|jdd�WYd}~dSd}~ww)Nrrr
rrrrrrrr�alternative�mixedr�From�To�plainr8�rbzContent-Disposition�
attachmentz - z%Y-%m-%d)�filenamer)r �Destinations�
RawMessager%r&r$r")r'r(rr)rr*r+r,r-r.r/rr�attach�openr�read�
add_header�strr	�today�strftime�send_raw_email�	as_stringr1r3rr2)r4r5r6r7r8r9r:�filerr;r<�multipart_content_subtype�msg�body�	file_pathrG�partr2r=r>r>r?�send_ses_email_with_attachment>s`�
�


��

� ��rZc@seZdZdd�ZdS)�
SESHandlerc	
Cs�tjdtjdtjdtjdd�}|�|�}|j}|j}|j}z|j|d|id|idd	|d
�id�d�}Wnt	yR}zt
|jd
d�WYd}~dSd}~wwt
d�|d|��dS)Nrrr
rrrrrzUTF-8)�Charsetrrrr$r"zEmail sent Message ID: {} - {}r&)r'r(rr)r3�toaddrs�fromaddrr6r0rr1r2)	�self�recordr�message�to_addresses�from_addressr6r2r=r>r>r?�emitys2�
���
�	 ��zSESHandler.emitN)�__name__�
__module__�__qualname__rdr>r>r>r?r[xsr[)r
r
r
r
r
)r
r
r
r
r
N)r'�logging.handlersr�botocore.exceptionsr�flaskr�'buyercall.blueprints.partnership.modelsr�email.mime.applicationr�email.mime.multipartr�email.mime.textrr	r@rZr[r>r>r>r?�<module>s
2
�: