
    4yi                     <    d dl Z d dlmZ d dlmZmZ  G d d      Zy)    N)ConnectionConfig)ConnectionErrorsPydanticClassRequiredc                   8    e Zd ZdZdeddfdZd	dZd
dZd
dZy)
ConnectionzK
    Manages Connection to provided email service with its credentials
    settingsreturnNc                 H    t        |t              st        d      || _        y )Nz<Configuration should be provided from ConnectionConfig class)
isinstancer   r   r   )selfr   s     Y/var/www/html/content_weaver/venv/lib/python3.12/site-packages/fastapi_mail/connection.py__init__zConnection.__init__   s&    ($45'N  !    c                 B   K   | j                          d{    | S 7 w)z)
        Setting up a connection
        N)_configure_connection)r   s    r   
__aenter__zConnection.__aenter__   s$      ((*** 	+s   c                    K   | j                   j                  s#| j                  j                          d{    yy7 w)z(
        Closing the connection
        N)r   SUPPRESS_SENDsessionquit)r   exc_typeexctbs       r   	__aexit__zConnection.__aexit__   s3      }}**,,##%%% +%s   4?=?c           
      .  K   	 t        j                  | j                  j                  | j                  j                  | j                  j
                  | j                  j                  | j                  j                  | j                  j                  | j                  j                  | j                  j                        | _        | j                  j                  s| j                  j                          d {    | j                  j                  r[| j                  j                  | j                  j                   | j                  j"                  j%                                d {    y y y 7 w7 	# t&        $ r}t)        d| d      d }~ww xY ww)N)hostnametimeoutportuse_tls	start_tlsvalidate_certslocal_hostnamecert_bundlezException raised z7, check your credentials or email service configuration)
aiosmtplibSMTPr   MAIL_SERVERTIMEOUT	MAIL_PORTMAIL_SSL_TLSMAIL_STARTTLSVALIDATE_CERTSLOCAL_HOSTNAMECERT_BUNDLEr   r   connectUSE_CREDENTIALSloginMAIL_USERNAMEMAIL_PASSWORDget_secret_value	Exceptionr   )r   errors     r   r   z Connection._configure_connection!   s2    	%??22--]],,22--55#}};;#}};; MM55	DL ==..ll**,,,==00,,,,3333DDF   1 /,
  	"#E7*ab 	sN   FC5E5 9E1:A/E5 )E3*E5 .F1E5 3E5 5	F>FFF)r	   r   )r	   N)	__name__
__module____qualname____doc__r   r   r   r   r    r   r   r   r      s*    !!1 !d !&r   r   )r$   fastapi_mail.configr   fastapi_mail.errorsr   r   r   r:   r   r   <module>r=      s     0 G3 3r   