o
    ahk                     @   s@   d dl mZ d dlmZ d dlmZ d dlZG dd deZdS )    )BaseCommand)	send_mail)settingsNc                   @   s    e Zd ZdZdd Zdd ZdS )Commandz2Test email configuration in production environmentc                 C   s   |j dtddd d S )Nz--toTz#Email address to send test email to)typerequiredhelp)add_argumentstr)selfparser r   X/var/www/html/optinet_system/django_project/management/commands/test_production_email.pyadd_arguments
   s   
zCommand.add_argumentsc                 O   s  |d }| j | jd | j dtjdd  | j dttdd  | j d	ttd
d  | j dttdd  | j dttdd  | j dttdd  | j dttdd  | j dttdd  z6ddl	m
} |jjdd}| j d |D ]}|jr|jrdnd}n|jpd}| j |j d|  qW n ty } z| j d|  W Y d }~nd }~ww | j d| d  zAd!}	d"tjdd d#ttdd d$ttd
d d%ttdd d&	}
t|	|
ttdd'|gdd( | j | jd)| d* W d S  tyU } z4| j | jd+t|  | j d, | j d- | j d. | j d/ | j d0 W Y d }~d S d }~ww )1Ntoz+=== Production Email Configuration Test ===zEnvironment: DJANGO_SETTINGS_MODULEzNot setzEmail Backend: EMAIL_BACKENDzNot configuredzEmail Host: 
EMAIL_HOSTzEmail Port: 
EMAIL_PORTzEmail User: EMAIL_HOST_USERz	Use TLS: EMAIL_USE_TLSFz	Use SSL: EMAIL_USE_SSLzFrom Email: DEFAULT_FROM_EMAILr   )SystemSettingsemail)categoryz
Database Email Settings:z[HIDDEN]z	[NOT SET]z: z!Error reading database settings: z
Sending test email to z...z)Production Email Test - OptiNet Solutionsz
Production Email Test Successful!

This email was sent from your production server to verify email configuration.

Server Details:
- Environment: Production
- Django Settings: z
- Email Backend: z
- Email Host: z
- Email Port: z

If you received this email, your production email configuration is working correctly!

Best regards,
OptiNet Solutions Team
            znoreply@optinet.co.ke)subjectmessage
from_emailrecipient_listfail_silentlyu$   ✅ Test email sent successfully to !u   ❌ Failed to send test email: z
=== Troubleshooting Tips ===zP1. Check your email credentials in the database (Settings > Email Configuration)z42. Verify SMTP server settings (host, port, TLS/SSL)z13. Test with a different email provider if neededz=4. Check if your server's IP is blocked by the email provider)stdoutwritestyleSUCCESSosenvirongetgetattrr   settings.modelsr   objectsfilteris_sensitivevaluekey	Exceptionr   ERRORr
   )r   argsoptions
test_emailr   db_settingssettingr.   er   r   r   r   r   handle   sr   


	



zCommand.handleN)__name__
__module____qualname__r   r   r8   r   r   r   r   r      s    r   )django.core.management.baser   django.core.mailr   django.confr   r&   r   r   r   r   r   <module>   s
   