
    3i                         d 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  ej                  ej                  d	        ej                  e      Z G d
 de      ZddZy)zc
Description: This file contains the EmailThread
class which is used to send emails asynchronously
    N)Thread)settings)EmailMessage)get_template)CompanyInfoz4%(asctime)s - %(name)s - %(levelname)s - %(message)s)levelformatc                       e Zd ZdZddZd Zy)EmailThreadz
    This class is used to send emails asynchronously.

    Attributes:
        subject (str): The subject of the email.
        html_content (str): The content of the email.
        recipient_list (list): The list of recipients.

    Nc                 t    || _         || _        || _        || _        || _        t        j                  |        y N)subjectkeyrecipient_listhtml_contentfilesr   __init__)selfr   r   r   r   r   s         C/var/www/html/dp2/backend_v2.1/server/utils/threads/email_thread.pyr   zEmailThread.__init__    s3    ,(
    c                 v   	 t        | j                        j                  | j                        }t	        | j
                  |t        j                  dz   t        j                  z   dz   | j                        }d|_
        |j                          y# t        $ r }t        j                  d|       Y d}~yd}~ww xY w)z' This Function used for run the thread <>htmlz%sN)r   r   renderr   r   r   r   EMAIL_FROM_HEADER
FROM_EMAILr   content_subtypesend	Exceptionloggererror)r   messagemsg	exceptions       r   runzEmailThread.run(   s    		*"4#4#45<<TXXFGt||W'99#=@S@SSVYY[_[n[npC"(CHHJ 	*LLy))	*s   BB 	B8B33B8r   )__name__
__module____qualname____doc__r   r&    r   r   r   r      s    *r   r   c                    t         j                  j                         }|r|j                  |j                  |j
                  |j                  |j                  |j                  r|j                  j                  nt        j                  |j                  |j                  |j                  |j                  |j                   |j"                  d}t$        j'                  d       nt        j(                  t        j*                  t        j,                  t        j.                  t        j0                  t        j                  t        j2                  t        j4                  t        j6                  t        j8                  t        j:                  t        j<                  d}|j?                  |       	 tA        | ||||      jC                          t$        j'                  d|f       y# tD        $ r}t$        jG                  |       Y d}~yd}~ww xY w)a   This module is used for send email in the whole system.
        This function run asynchronously.
        Args:
            subject (str): The subject of the email.
            html_content (str): The content of the email.
            recipient_list (list): The list of recipients.
            key (dict): The dictionary of key value pairs.
            files (list): The list of files.
       )company_namecompany_addresscompany_emailcompany_phonecompany_websitecompany_logo
text_colorprimary_colorsecondary_color	copyrightbutton_colorstarting_yearzUsing CompanyInfo from databasezEmail sent to:%sN)$r   objectsfirstr-   r.   r/   r0   r1   r2   urlr   COMPANY_LOGOcompany_text_colorcompany_primary_colorcompany_secondary_colorcompany_copyrightcompany_button_colorcompany_starting_yearr!   infoCOMPANY_NAMECOMPANY_ADDRESSCOMPANY_EMAILCOMPANY_PHONECOMPANY_WEBSITE
TEXT_COLORPRIMARY_COLORSECONDARY_COLORCOMPANY_COPYRIGHTBUTTON_COLORSTARTING_YEARupdater   startr    r"   )r   r   r   r   r   company_infocompany_informationr%   s           r   	send_mailrS   6   s    &&,,.L )55+;;)77)77+;;=I=V=VL5599\d\q\q&99)??+CC%77(==)??
 	56 %11'77%33%33'77$11"--%33'77!33$11%33
 JJ"# G\>3FLLN'89  Y s   -4G" "	H
+HH
)NN)r*   loggingloggers	threadingr   django.confr   django.core.mailr   django.template.loaderr   apps.core.modelsr   basicConfigDEBUG	getLoggerr'   r!   r   rS   r+   r   r   <module>r^      s^   
     ) / (   '--QS 
		8	$
*& *B4 r   