U
    0f	                     @   sx   d dl Z d dlmZ d dlmZ d dlZd dlZd dlmZm	Z	m
Z
 d dlZe ZeedZeefddZdS )    N)MIMEText)MIMEMultipart)datetime	timedeltadatez%Y-%m-%d %H:%M:%Sc              
   C   s4  d}ddg}d}d}d}t  }	tj||f|	d< d||	d	< | |	d
< d| d| d| d}
|	t|
d | }|	t|d zLtdd$}|	|| |
|||	  W 5 Q R X td td W n\ tk
r. } z<td|  td td tjddd td W 5 d }~X Y nX d S )Nzpostmancollection7@gmail.comzkriyans.p@upsquare.inzvivek.f@upsquare.inZixaqylsiglqpivgfz
VPN Scriptz Python Script Exception OccurredFromz, ToZSubjectzs
        <html>
            <body>
                <p style="font-size: 20px"><strong>Script Running Stopped in <u>zY</u></strong></p>
                <p style="font-size: 20px"><strong>Server IP: </strong>zQ</p>
                <p style="font-size: 20px"><strong>Exception time: </strong>z</p>
                <p style="font-size: 20px"><strong> Exception message: </strong></p>
            </body>
        </html>
        htmlplainzsmtp.gmail.comi  z)Exception report email sent successfully!zl-----------------------------------------------EXCEPTION_MAIL_SENT------------------------------------------z'Failed to send exception report email: zl-----------------------------------------------MAIL_EXCEPTION_LOG-------------------------------------------zSend Mail errorT)exc_infoza-------------------------------------------------------------------------------------------------)r   emailutils
formataddrjoinattachr   smtplibSMTP_SSLloginsendmail	as_stringprintlogginginfo	Exceptionerror)Zexception_msgscript_name	server_ipZe_timeZsender_emailZreceiver_emailspasswordZexception_titleZexception_subjectmessagebodyZbody_exceptionservere r"   &/var/www/html/ovpn/vpnGate/sendmail.pysendExceptionMail   s>    


r$   )r   email.mime.textr   email.mime.multipartr   email.utilsr   r   r   r   r   timeZ	mail_timefromtimestampstrftimeZmail_time_formattedstrr$   r"   r"   r"   r#   <module>   s   