
    Shs                     >   d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZmZmZmZ ddlZddlZddlZdd	lmZmZmZmZmZmZmZmZ  ej        e          Z  G d
 d          Z! e!            Z"	 	 	 	 d$de#de#deee#ef                  dee$         deee#e#f                  deee#                  de%fdZ&	 	 	 d%de#de#de#dee'         dee         dee         de%fdZ(	 d&de#de#de#deee#ef                  de%f
dZ)de#d e#d!ede%fd"Z*de%fd#Z+dS )'z
Email notification service for critical errors and system failures.
This module provides automatic email notifications when critical errors occur.
    N)MIMEText)MIMEMultipart)MIMEBase)encoders)datetime)DictAnyOptionalList)EMAIL_SMTP_SERVEREMAIL_SMTP_PORTEMAIL_USERNAMEEMAIL_PASSWORDEMAIL_RECIPIENTSEMAIL_FROM_ADDRESSEMAIL_USE_TLSEMAIL_USE_SSLc                      e Zd ZdZd Zd Z	 	 	 	 d(dededeeee	f                  dee
         d	eeeef                  d
eee                  defdZ	 	 	 d)dedededee         dee         dee         defdZ	 d*dedededeeee	f                  def
dZ	 	 	 d)dededeeee	f                  dee
         d	eeeef                  defdZ	 	 	 d)dedededee         dee         dee         defdZ	 d+dedededeeee	f                  def
dZd,dededed
ee         def
dZd ed!ed"edefd#Zd ed$ed%edefd&Zdefd'ZdS )-EmailNotifierz@Email notification service for critical errors and system alertsc                     t           | _        t          | _        t          | _        t          | _        t          | _	        t          | _        t          | _        t          | _        |                                  dS )z5Initialize the email notifier with SMTP configurationN)r   smtp_serverr   	smtp_portr   usernamer   passwordr   
recipientsr   from_addressr   use_tlsr   use_ssl_validate_config)selfs    A/var/www/html/testcasegenerator.evdpl.com/utils/email_notifier.py__init__zEmailNotifier.__init__   sV    ,(&&*.$$ 	    c                 d   d| j         fd| j        fd| j        fd| j        fd| j        fd| j        fg}g }|D ]\  }}|s|                    |           |r9t                              dd	                    |                      d	| _
        dS d
| _
        t                              d           dS )zValidate email configurationSMTP_SERVER	SMTP_PORTUSERNAMEPASSWORD
RECIPIENTSFROM_ADDRESSz5Email notification disabled - missing configuration: , FTz3Email notification service initialized successfullyN)r   r   r   r   r   r   appendloggerwarningjoinenabledinfo)r    required_configsmissing_configsnamevalues        r!   r   zEmailNotifier._validate_config*   s     D,-$.)''4?+T./
 + 	- 	-KD% -&&t,,, 	ONNoSWS\S\]lSmSmooppp DLLLDLKKMNNNNNr#   N
error_typeerror_messagecontext	exceptionuser_contextr   returnc                 >   | j         st                              d           dS 	 d| d}|                     |||||          }|                     ||d|          S # t
          $ r5}	t                              dt          |	                      Y d}	~	dS d}	~	ww xY w)	a  
        Send critical error notification email
        
        Args:
            error_type: Type of error (API_FAILURE, SYSTEM_ERROR, etc.)
            error_message: Error message
            context: Additional context data
            exception: Exception object if available
            user_context: User information if available
            
        Returns:
            bool: True if email sent successfully, False otherwise
        zCEmail notifications disabled - skipping critical error notificationFu   🚨 CRITICAL ERROR ALERT -  - AI Test Case GeneratorTis_htmlr   z,Failed to send critical error notification: N)r0   r-   r.   _create_error_email_body_send_email	Exceptionerrorstr)
r    r6   r7   r8   r9   r:   r   subjectbodyes
             r!    send_critical_error_notificationz.EmailNotifier.send_critical_error_notificationA   s    $ | 	NN`aaa5	ZZZZZG 00M7I| D
 ##GT4J#WWW 	 	 	LLPAPPQQQ55555	   7A 
B'*BBapi_nameendpointstatus_coderesponse_datarequest_datac                 >   | j         st                              d           dS 	 d| d}|                     ||||||          }|                     ||d          S # t
          $ r5}	t                              dt          |	                      Y d}	~	dS d}	~	ww xY w)	a  
        Send API failure notification email
        
        Args:
            api_name: Name of the API (OpenAI, Jira, Azure, etc.)
            endpoint: API endpoint that failed
            error_message: Error message
            status_code: HTTP status code if available
            response_data: API response data if available
            request_data: Request data if available
            
        Returns:
            bool: True if email sent successfully, False otherwise
        z@Email notifications disabled - skipping API failure notificationFu   ⚠️ API FAILURE - r=   Tr?   z)Failed to send API failure notification: N)r0   r-   r.   _create_api_failure_email_bodyrA   rB   rC   rD   )
r    rJ   rK   r7   rL   rM   rN   rE   rF   rG   s
             r!   send_api_failure_notificationz+EmailNotifier.send_api_failure_notificationf   s    $ | 	NN]^^^5	QhQQQG 66(M;| D
 ##GT4#@@@ 	 	 	LLMSVVMMNNN55555	rI   WARNING
alert_typemessageseverityc                 b   | j         st                              d           dS 	 |dk    rdn	|dk    rdnd}| d| d	}|                     ||||          }|                     ||d
          S # t
          $ r5}t                              dt          |                      Y d}~dS d}~ww xY w)a{  
        Send system alert notification
        
        Args:
            alert_type: Type of alert (PERFORMANCE, SECURITY, etc.)
            message: Alert message
            severity: Alert severity (INFO, WARNING, CRITICAL)
            context: Additional context data
            
        Returns:
            bool: True if email sent successfully, False otherwise
        z4Email notifications disabled - skipping system alertFCRITICAL   🔴rS      🟡   🔵z SYSTEM ALERT - r=   TrP   zFailed to send system alert: N)r0   r-   r.   _create_system_alert_email_bodyrA   rB   rC   rD   )	r    rT   rU   rV   r8   emojirE   rF   rG   s	            r!   send_system_alertzEmailNotifier.send_system_alert   s     | 	NNQRRR5	&*44FFHPYDYDY&&_eEUU
UUUG 77
GXW^__D ##GT4#@@@ 	 	 	LLAQAABBB55555	s   A	A/ /
B.9*B))B.c                    t          j                                        d          }d}|rF	 d                    t	          j        t          |          ||j                            }n	#  d}Y nxY wd}|rdt          j	        |d           d}d}	|r5dd                    d	 |
                                D                        d
}	d}
|rd| d}
d| d| d| d|	 d| d|
 d}|S )z*Create HTML email body for critical errors%Y-%m-%d %H:%M:%S UTC zUnable to extract traceback   
            <h3>📋 Additional Context:</h3>
            <pre style="background-color: #f5f5f5; padding: 10px; border-radius: 5px; overflow-x: auto;">   indent</pre>
            uN   
            <h3>👤 User Information:</h3>
            <ul>
                c                 &    g | ]\  }}d | d| dS )z<li><strong>z:</strong> z</li> ).0kvs      r!   
<listcomp>z:EmailNotifier._create_error_email_body.<locals>.<listcomp>   s0    aaaDAq???q???aaar#   z
            </ul>
            u   
            <h3>🔍 Stack Trace:</h3>
            <pre style="background-color: #f5f5f5; padding: 10px; border-radius: 5px; overflow-x: auto; font-size: 12px;">u  
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8">
            <title>Critical Error Alert</title>
        </head>
        <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
            <div style="max-width: 800px; margin: 0 auto; padding: 20px;">
                <div style="background-color: #dc3545; color: white; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h1 style="margin: 0; font-size: 24px;">🚨 CRITICAL ERROR ALERT</h1>
                    <p style="margin: 10px 0 0 0; font-size: 16px;">AI Test Case Generator System</p>
                </div>
                
                <div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h2 style="color: #dc3545; margin-top: 0;">Error Details</h2>
                    <p><strong>⏰ Timestamp:</strong> u>   </p>
                    <p><strong>🔧 Error Type:</strong> u  </p>
                    <p><strong>📝 Error Message:</strong></p>
                    <div style="background-color: #fff; padding: 15px; border-left: 4px solid #dc3545; margin: 10px 0;">
                        <code style="color: #dc3545; font-size: 14px;">[</code>
                    </div>
                </div>
                
                
                u  
                
                <div style="background-color: #e9ecef; padding: 15px; border-radius: 5px; margin-top: 20px;">
                    <h3>🔧 Recommended Actions:</h3>
                    <ul>
                        <li>Check the application logs for more details</li>
                        <li>Verify system resources and connectivity</li>
                        <li>Review recent deployments or configuration changes</li>
                        <li>Monitor system performance and user impact</li>
                    </ul>
                </div>
                
                <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #dee2e6;">
                    <p style="color: #6c757d; font-size: 12px;">
                        This is an automated alert from the AI Test Case Generator monitoring system.
                    </p>
                </div>
            </div>
        </body>
        </html>
        )r   nowstrftimer/   	tracebackformat_exceptiontype__traceback__jsondumpsitems)r    r6   r7   r8   r9   r:   	timestamptraceback_infocontext_html	user_htmltraceback_html	html_bodys               r!   r@   z&EmailNotifier._create_error_email_body   s    LNN++,CDD	  	??!#)COOY	0G* * " "?!>  	jnjtu|  FG  kH  kH  kH  L 	 	 aaLL^L^L`L`aaabb  I  	 |J  N
.  9B!. ." ;E#. .( IV). .0 1. .2 3. .4  5. . .	` s   ;A( (A.c                 
   t          j                                        d          }d}|rdt          j        |d           d}d}	|rdt          j        |d           d}	d| d	| d
| d|rd| dnd d| d|	 d| d}
|
S )z'Create HTML email body for API failuresr`   ra   u   
            <h3>📤 API Response:</h3>
            <pre style="background-color: #f5f5f5; padding: 10px; border-radius: 5px; overflow-x: auto;">rc   rd   rf   u   
            <h3>📥 Request Data:</h3>
            <pre style="background-color: #f5f5f5; padding: 10px; border-radius: 5px; overflow-x: auto;">u  
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8">
            <title>API Failure Alert</title>
        </head>
        <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
            <div style="max-width: 800px; margin: 0 auto; padding: 20px;">
                <div style="background-color: #fd7e14; color: white; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h1 style="margin: 0; font-size: 24px;">⚠️ API FAILURE ALERT</h1>
                    <p style="margin: 10px 0 0 0; font-size: 16px;">AI Test Case Generator System</p>
                </div>
                
                <div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h2 style="color: #fd7e14; margin-top: 0;">API Failure Details</h2>
                    <p><strong>⏰ Timestamp:</strong> u<   </p>
                    <p><strong>🔌 API Name:</strong> uB   </p>
                    <p><strong>🌐 Endpoint:</strong> <code>z </code></p>
                    uD   <p><strong>📊 Status Code:</strong> <span style="color: #dc3545;">z</span></p>u  
                    <p><strong>📝 Error Message:</strong></p>
                    <div style="background-color: #fff; padding: 15px; border-left: 4px solid #fd7e14; margin: 10px 0;">
                        <code style="color: #dc3545; font-size: 14px;">rm   rn   u  
                
                <div style="background-color: #e9ecef; padding: 15px; border-radius: 5px; margin-top: 20px;">
                    <h3>🔧 Recommended Actions:</h3>
                    <ul>
                        <li>Check API service status and connectivity</li>
                        <li>Verify API credentials and authentication</li>
                        <li>Review API rate limits and quotas</li>
                        <li>Check for API endpoint changes or deprecations</li>
                        <li>Monitor API response times and error rates</li>
                    </ul>
                </div>
                
                <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #dee2e6;">
                    <p style="color: #6c757d; font-size: 12px;">
                        This is an automated alert from the AI Test Case Generator monitoring system.
                    </p>
                </div>
            </div>
        </body>
        </html>
        r   ro   rp   ru   rv   )r    rJ   rK   r7   rL   rM   rN   rx   response_htmlrequest_htmlr}   s              r!   rQ   z,EmailNotifier._create_api_failure_email_body	  s^    LNN++,CDD	  	jnjt  vC  LM  kN  kN  kN  M  	jnjt  vB  KL  kM  kM  kM  L
0  9B!0 0" 9A#0 0$ ?G%0 0& yD  Lt\gtttt  JL'0 0, IV-0 04 50 06 70 0 0	d r#   c                    t          j                                        d          }|dk    rdn	|dk    rdnd}|dk    rdn	|dk    rdnd	}d
}|rdt          j        |d           d}d| d| d| d| d| d| d| d| d| d| d| d}	|	S )z(Create HTML email body for system alertsr`   rX   z#dc3545rS   z#fd7e14z#17a2b8rY   rZ   r[   ra   rb   rc   rd   rf   aa  
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8">
            <title>System Alert</title>
        </head>
        <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
            <div style="max-width: 800px; margin: 0 auto; padding: 20px;">
                <div style="background-color: z; color: white; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h1 style="margin: 0; font-size: 24px;">a9   SYSTEM ALERT</h1>
                    <p style="margin: 10px 0 0 0; font-size: 16px;">AI Test Case Generator System</p>
                </div>
                
                <div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h2 style="color: u\   ; margin-top: 0;">Alert Details</h2>
                    <p><strong>⏰ Timestamp:</strong> u>   </p>
                    <p><strong>🚨 Alert Type:</strong> uO   </p>
                    <p><strong>⚡ Severity:</strong> <span style="color: z; font-weight: bold;">u   </span></p>
                    <p><strong>📝 Message:</strong></p>
                    <div style="background-color: #fff; padding: 15px; border-left: 4px solid zH; margin: 10px 0;">
                        <p style="margin: 0; color: z; font-size: 14px;">zX</p>
                    </div>
                </div>
                
                u  
                
                <div style="background-color: #e9ecef; padding: 15px; border-radius: 5px; margin-top: 20px;">
                    <h3>🔧 Recommended Actions:</h3>
                    <ul>
                        <li>Review system logs and monitoring dashboards</li>
                        <li>Check system resources and performance metrics</li>
                        <li>Verify system configuration and dependencies</li>
                        <li>Monitor for any user impact or service degradation</li>
                    </ul>
                </div>
                
                <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #dee2e6;">
                    <p style="color: #6c757d; font-size: 12px;">
                        This is an automated alert from the AI Test Case Generator monitoring system.
                    </p>
                </div>
            </div>
        </body>
        </html>
        r   )
r    rT   rU   rV   r8   rx   colorr]   rz   r}   s
             r!   r\   z-EmailNotifier._create_system_alert_email_bodyU  st    LNN++,CDD	 &33		hR[F[F[aj"j00I@U@Uff[a  	jnjtu|  FG  kH  kH  kH  L
- 05- - >C- - (-- -  9B!- -" ;E#- -$ LQ%- -$ iq%- -( `e)- -* 6;+- -* QX+- -2 3- - -	^ r#   TrE   rF   r?   c                    	 |r|n| j         }|st                              d           dS t          d          }||d<   | j        |d<   d                    |          |d<   |r$|                    t          |d                     n#|                    t          |d	                     | j        r5t          j
                    }t          j        | j        | j        |
          }n:t          j        | j        | j                  }| j        r|                                 |                    | j        | j                   |                    |           |                                 t                              dd                    |                      dS # t0          $ r5}	t                              dt3          |	                      Y d}	~	dS d}	~	ww xY w)ai  
        Send email using SMTP
        
        Args:
            subject: Email subject
            body: Email body
            is_html: Whether the body is HTML format
            recipients: List of email recipients (defaults to configured recipients)
            
        Returns:
            bool: True if email sent successfully, False otherwise
        zNo email recipients specifiedFalternativeSubjectFromr+   Tohtmlplain)r8   zEmail sent successfully to TzFailed to send email: N)r   r-   rC   r   r   r/   attachr   r   sslcreate_default_contextsmtplibSMTP_SSLr   r   SMTPr   starttlsloginr   r   send_messagequitr1   rB   rD   )
r    rE   rF   r?   r   email_recipientsmsgr8   serverrG   s
             r!   rA   zEmailNotifier._send_email  s   '	-7LzzT_# <===u  ..C$C	N+CK		"233CI  4

8D&112222

8D'22333 | &466 )$*:DNT[\\\ d&6GG< &OO%%% LL666$$$KKMMMKKSdii@P6Q6QSSTTT4 	 	 	LL:#a&&::;;;55555	s   'F E.F 
G%*GGemailreset_token
expires_atc                 x   | j         st                              d           dS 	 ddlm} d}| d| }|                    d          }|                     |||          }|                     ||d|g	          S # t          $ r5}	t          	                    d
t          |	                      Y d}	~	dS d}	~	ww xY w)a'  
        Send password reset email
        
        Args:
            email: User's email address
            reset_token: Password reset token
            expires_at: Token expiration time
            
        Returns:
            bool: True if email sent successfully, False otherwise
        z?Email notifications disabled - cannot send password reset emailFr   )BASE_URLu4   🔐 Password Reset Request - AI Test Case Generatorz/reset-password-confirm?token=z%B %d, %Y at %I:%M %p UTCTr>   z%Failed to send password reset email: N)r0   r-   r.   config.settingsr   rp   !_create_password_reset_email_bodyrA   rB   rC   rD   )
r    r   r   r   r   rE   
reset_linkexpires_strrF   rG   s
             r!   send_password_reset_emailz'EmailNotifier.send_password_reset_email  s     | 	NN\]]]5	000000LG %QQKQQJ %--.IJJK 99%[YYD ##GT4UG#TTT 	 	 	LLIQIIJJJ55555	s   AA: :
B9*B44B9r   r   c                 v    t          j                                        d          }d| d| d| d| d| d}|S )z)Create HTML email body for password resetr`   u  
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8">
            <title>Password Reset Request</title>
        </head>
        <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
            <div style="max-width: 600px; margin: 0 auto; padding: 20px;">
                <div style="background-color: #007bff; color: white; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h1 style="margin: 0; font-size: 24px;">🔐 Password Reset Request</h1>
                    <p style="margin: 10px 0 0 0; font-size: 16px;">AI Test Case Generator</p>
                </div>
                
                <div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-bottom: 20px;">
                    <h2 style="color: #007bff; margin-top: 0;">Reset Your Password</h2>
                    <p>Hello,</p>
                    <p>We received a request to reset your password for your AI Test Case Generator account associated with <strong>aC  </strong>.</p>
                    
                    <div style="background-color: #fff; padding: 20px; border-radius: 5px; margin: 20px 0; text-align: center;">
                        <p style="margin: 0 0 15px 0; font-weight: bold;">Click the button below to reset your password:</p>
                        <a href="a[  " style="display: inline-block; background-color: #007bff; color: white; padding: 12px 30px; text-decoration: none; border-radius: 5px; font-weight: bold; font-size: 16px;">
                            Reset My Password
                        </a>
                    </div>
                    
                    <p style="margin: 20px 0 10px 0;"><strong>Or copy and paste this link into your browser:</strong></p>
                    <div style="background-color: #e9ecef; padding: 10px; border-radius: 5px; word-break: break-all; font-family: monospace; font-size: 14px;">
                        u  
                    </div>
                </div>
                
                <div style="background-color: #fff3cd; border: 1px solid #ffeaa7; padding: 15px; border-radius: 5px; margin-bottom: 20px;">
                    <h3 style="color: #856404; margin-top: 0;">⚠️ Important Security Information</h3>
                    <ul style="color: #856404; margin: 0;">
                        <li>This link will expire on <strong>u  </strong></li>
                        <li>The link can only be used once</li>
                        <li>If you didn't request this password reset, please ignore this email</li>
                        <li>Your password will remain unchanged until you click the link above</li>
                    </ul>
                </div>
                
                <div style="background-color: #e9ecef; padding: 15px; border-radius: 5px; margin-bottom: 20px;">
                    <h3 style="margin-top: 0;">🔒 Security Tips</h3>
                    <ul style="margin: 0;">
                        <li>Choose a strong, unique password</li>
                        <li>Don't share your password with anyone</li>
                        <li>Log out of your account when using shared computers</li>
                        <li>Contact support if you notice any suspicious activity</li>
                    </ul>
                </div>
                
                <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #dee2e6;">
                    <p style="color: #6c757d; font-size: 12px; margin: 0;">
                        This email was sent on z<br>
                        If you have any questions, please contact our support team.
                    </p>
                </div>
            </div>
        </body>
        </html>
        )r   ro   rp   )r    r   r   r   rx   r}   s         r!   r   z/EmailNotifier._create_password_reset_email_body  s     LNN++,CDD	=" FK#= =* #-+= =8 $9= =F ?JG= =l 1:m= = =	~ r#   c                 V   | j         st                              d           dS 	 d}dt          j                                        d           d}|                     ||d          S # t          $ r5}t                              d	t          |                      Y d
}~dS d
}~ww xY w)z
        Test email configuration by sending a test email
        
        Returns:
            bool: True if test email sent successfully, False otherwise
        z8Email notifications disabled - cannot test configurationFu6   🧪 Email Configuration Test - AI Test Case Generatoru  
            <!DOCTYPE html>
            <html>
            <head>
                <meta charset="UTF-8">
                <title>Email Test</title>
            </head>
            <body style="font-family: Arial, sans-serif; line-height: 1.6; color: #333;">
                <div style="max-width: 600px; margin: 0 auto; padding: 20px;">
                    <div style="background-color: #28a745; color: white; padding: 20px; border-radius: 10px; text-align: center;">
                        <h1 style="margin: 0;">✅ Email Configuration Test Successful</h1>
                    </div>
                    <div style="background-color: #f8f9fa; padding: 20px; border-radius: 10px; margin-top: 20px;">
                        <p><strong>Timestamp:</strong> r`   aq  </p>
                        <p><strong>Service:</strong> AI Test Case Generator</p>
                        <p><strong>Status:</strong> Email notifications are working correctly</p>
                    </div>
                    <div style="text-align: center; margin-top: 30px; padding-top: 20px; border-top: 1px solid #dee2e6;">
                        <p style="color: #6c757d; font-size: 12px;">
                            This is a test email to verify email notification configuration.
                        </p>
                    </div>
                </div>
            </body>
            </html>
            TrP   zFailed to send test email: N)
r0   r-   r.   r   ro   rp   rA   rB   rC   rD   )r    rE   rF   rG   s       r!   test_email_configurationz&EmailNotifier.test_email_configuration9  s     | 	NNUVVV5!	NG 9A8O8OPg8h8h  D6 ##GT4#@@@ 	 	 	LL?s1vv??@@@55555	s   AA) )
B(3*B##B(NNNNNNNrS   N)N)TN)__name__
__module____qualname____doc__r"   r   rD   r
   r   r	   rB   r   boolrH   intrR   r^   r@   rQ   r\   rA   r   r   r   r   rh   r#   r!   r   r      s       JJ     O O O0 LPHLPTIM	# #3 #s #08c3h0H#2:92E# 6>d38n5M# 4<DI3F	# SW	# # # #L VZDHCG# #c #S #36#EMc]#3;D># 3;4.# MQ# # # #L Y] C # #&=Ed3PS8n=Uae   B EIAEIM\ \3 \s \)1$sCx.)A\+3I+>\ /7tCH~.F\ SV\ \ \ \~ W[EIDHJ Js Jc J47JFNsmJ4<TNJ 4<D>J NQJ J J JZ Z^A A# A A03A>FtCQTH~>VAbeA A A AF4 43 4c 4D 4UYZ]U^ 4jn 4 4 4 4l#s # #RZ #_c # # # #JDs D DZ] Dbe D D D DL,$ , , , , , ,r#   r   r6   r7   r8   r9   r:   r   r;   c                 @    t                               | |||||          S )z&Send critical error notification email)email_notifierrH   )r6   r7   r8   r9   r:   r   s         r!   rH   rH   k  s)     ::M7I|Z  r#   rJ   rK   rL   rM   rN   c                 @    t                               | |||||          S )z#Send API failure notification email)r   rR   )rJ   rK   r7   rL   rM   rN   s         r!   rR   rR   u  s)    
 77(M;|  r#   rS   rT   rU   rV   c                 <    t                               | |||          S )z$Send system alert notification email)r   r^   )rT   rU   rV   r8   s       r!   r^   r^   ~  s     ++J7SSSr#   r   r   r   c                 :    t                               | ||          S )zSend password reset email)r   r   )r   r   r   s      r!   r   r     s    33E;
SSSr#   c                  4    t                                           S )zTest email configuration)r   r   rh   r#   r!   r   r     s    22444r#   r   r   r   ),r   r   r   loggingemail.mime.textr   email.mime.multipartr   email.mime.baser   r   r   r   typingr   r	   r
   r   osrq   ru   r   r   r   r   r   r   r   r   r   	getLoggerr   r-   r   r   rD   rB   r   rH   r   rR   r^   r   r   rh   r#   r!   <module>r      s6   
  



  $ $ $ $ $ $ . . . . . . $ $ $ $ $ $             , , , , , , , , , , , , 				                        
 
	8	$	$L	 L	 L	 L	 L	 L	 L	 L	^  HLDHLPEI	  S ,4T#s(^,D.6y.A 2:$sCx.1I 08S	/B	 OS	    RV@D?C C 3 /2AI#/7~ /7tn IM    UYT T# T T"T9A$sCx.9QT]aT T T T
TS Ts T TUY T T T T5$ 5 5 5 5 5 5r#   