o
    Q;ig                     @   s`   d dl mZ d dlmZ d dl mZ d dlZd dlmZ d dlm	Z	 dd Z
d	d
 Zdd ZdS )    )EmailMultiAlternatives)settings)get_connectionN)render_to_string)loggerc                  C   s&   t tjtjtjtjtjd} | tjfS )zB
    Get the email connection and sender email from settings.
    )hostportusernamepassworduse_tls)r   r   
EMAIL_HOST
EMAIL_PORTEMAIL_HOST_USEREMAIL_HOST_PASSWORDEMAIL_USE_TLS
connection r   (/var/www/html/premium_crap/core/email.pyget_info_connection   s   
r   c                    s*    fdd}t j|d  dS )zBackground email taskc                      s   t   d S )N)send_support_emailr   country_codeemailmessagenamephonesubjectr   r   task   s   z&send_support_email_async.<locals>.task)targetN)	threadingThreadstart)r   r   r   r   r   r   r   r   r   r   send_support_email_async   s   r#   c                 C   s   t d t \}}d}d|  d| d| d| d| d| d	}	d
| d| }|	}
| d| }|}t||
||g|d}d|_z| }t d|  W dS  tyo } ztjddd t dt| W Y d}~dS d}~ww )z2
    Send an email of contact us to the user.
    z>>>>>>>>>>>>>>>in mailzPremium Crapz#
        <p><strong>Name:</strong> z(</p>
        <p><strong>Email:</strong> z(</p>
        <p><strong>Phone:</strong>  z*</p>
        <p><strong>Subject:</strong> z*</p>
        <p><strong>Message:</strong> z	</p>
    zContact Us with z - r   htmlzEmail sent count: zError in send_contact_us_emailT)exc_infozEmail sending failed:N)	printr   r   content_subtypesend	Exceptionr   errorstr)r   r   r   r   r   r   r   
from_emailapp_namehtml_contentbodysend_from_emailto_emailemail_messagesenter   r   r   r   )   s<   
r   )django.core.mailr   django.confr   r   r    django.template.loaderr   core.loggerr   r   r#   r   r   r   r   r   <module>   s    