
    A[iO                     l    S SK r S SKJr  S SKJr  S SKJr  S SKJr  S SK	r	S SK
Jr  S SKr " S S5      rg)	    N)MIMEText)MIMEMultipart)MIMEBase)encoders)Optionalc                   (   \ rS rSrSr       S S\S\S\S\S\S	\S
\4S jjr S!S\S\S\S\\   S\	4
S jjr
 S!S\S\S\S\\   S\4
S jjrS\S\S\S\S\S\	4S jr S!S\S\S\S\\   S\4
S jjrS\S\S\S\S\S\4S jrS\	S\S\4S jrSrg)"EmailSender   z Email sending service using SMTPNhostportusernamepassword
encryptionfrom_address	from_namec                 H   Xl         X l        U=(       d    [        R                  " S5      U l        U=(       d    [        R                  " S5      U l        UR                  5       U l        U=(       d)    [        R                  " S5      =(       d    U R                  U l        U=(       d    [        R                  " SS5      U l	        [        R                  " [        5      U l        U R                  (       a  U R
                  (       d  U R                  R                  S5        gg)a  
Initialize email sender

Args:
    host: SMTP server host
    port: SMTP server port
    username: SMTP username/email
    password: SMTP password (app password for Gmail)
    encryption: Encryption type (ssl or tls)
    from_address: From email address
    from_name: From name
MAIL_USERNAMEMAIL_PASSWORDMAIL_FROM_ADDRESSMAIL_FROM_NAME
Troy RideszSMTP credentials not configuredN)r   r   osgetenvr   r   lowerr   r   r   logging	getLogger__name__loggerwarning)selfr   r   r   r   r   r   r   s           "/var/www/html/troy/email_sender.py__init__EmailSender.__init__   s    ( 		 >BIIo$> >BIIo$>$**,([BII6I,J[dmm"Obii0@,&O''1}}DMMKK AB %2    recipient_emailestimate_farepayment_linkcustomer_namereturnc                 T   [        S5      nU R                   SU R                   S3US'   XS'   SUS'   U(       a  SU S	3OS
nSU SU SU SU SU SU R                   S3nSU SU SU S3n[        US5      n	[        US5      n
UR	                  U	5        UR	                  U
5        U$ )a  
Create email template for fare estimate

Args:
    recipient_email: Recipient email address
    estimate_fare: Estimated fare amount
    payment_link: Payment link URL
    customer_name: Optional customer name
    
Returns:
    MIMEMultipart email message
alternative <>FromToz$Your Ride Fare Estimate - Troy RidesSubjectzHello ,zHello,u9  
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8">
            <style>
                body {
                    font-family: Arial, sans-serif;
                    line-height: 1.6;
                    color: #333;
                    max-width: 600px;
                    margin: 0 auto;
                    padding: 20px;
                }
                .container {
                    background-color: #f9f9f9;
                    border-radius: 10px;
                    padding: 30px;
                    margin: 20px 0;
                }
                .header {
                    background-color: #2c3e50;
                    color: white;
                    padding: 20px;
                    border-radius: 10px 10px 0 0;
                    text-align: center;
                }
                .header h1 {
                    margin: 0;
                    font-size: 24px;
                }
                .content {
                    background-color: white;
                    padding: 30px;
                    border-radius: 0 0 10px 10px;
                }
                .fare-box {
                    background-color: #3498db;
                    color: white;
                    padding: 20px;
                    border-radius: 8px;
                    text-align: center;
                    margin: 20px 0;
                }
                .fare-amount {
                    font-size: 36px;
                    font-weight: bold;
                    margin: 10px 0;
                }
                .payment-button {
                    display: inline-block;
                    background-color: #27ae60;
                    color: white;
                    padding: 15px 30px;
                    text-decoration: none;
                    border-radius: 5px;
                    font-weight: bold;
                    margin: 20px 0;
                    font-size: 16px;
                }
                .payment-button:hover {
                    background-color: #229954;
                }
                .footer {
                    text-align: center;
                    margin-top: 30px;
                    padding-top: 20px;
                    border-top: 1px solid #ddd;
                    color: #777;
                    font-size: 12px;
                }
                .info-box {
                    background-color: #ecf0f1;
                    padding: 15px;
                    border-radius: 5px;
                    margin: 20px 0;
                    border-left: 4px solid #3498db;
                }
            </style>
        </head>
        <body>
            <div class="container">
                <div class="header">
                    <h1>🚗 Troy Rides</h1>
                </div>
                <div class="content">
                    <p>a`  </p>
                    
                    <p>Thank you for choosing Troy Rides! We're excited to provide you with transportation services.</p>
                    
                    <div class="fare-box">
                        <p style="margin: 0 0 10px 0; font-size: 14px;">Estimated Fare</p>
                        <div class="fare-amount">$a6  </div>
                    </div>
                    
                    <p>Please review your fare estimate above. To proceed with your booking, please complete the payment using the link below:</p>
                    
                    <div style="text-align: center;">
                        <a href="uI  " class="payment-button">💳 Pay Now</a>
                    </div>
                    
                    <div class="info-box">
                        <p style="margin: 0;"><strong>Payment Link:</strong></p>
                        <p style="margin: 5px 0 0 0; word-break: break-all;">
                            <a href="z" style="color: #3498db;">a  </a>
                        </p>
                    </div>
                    
                    <p>If you have any questions or need assistance, please don't hesitate to contact us.</p>
                    
                    <p>Best regards,<br>
                    <strong>Troy Rides Team</strong></p>
                </div>
                <div class="footer">
                    <p>This is an automated email. Please do not reply to this message.</p>
                    <p>&copy; m. All rights reserved.</p>
                </div>
            </div>
        </body>
        </html>
        z5
        Troy Rides - Fare Estimate
        
        z
        
        Thank you for choosing Troy Rides! We're excited to provide you with transportation services.
        
        Estimated Fare: $zs
        
        To proceed with your booking, please complete the payment using the link below:
        
        a  
        
        If you have any questions or need assistance, please don't hesitate to contact us.
        
        Best regards,
        Troy Rides Team
        
        ---
        This is an automated email. Please do not reply to this message.
        plainhtmlr   r   r   r   attach)r    r%   r&   r'   r(   msggreetinghtml_contenttext_contentpart1part2s              r!   create_fare_estimate_email&EmailSender.create_fare_estimate_email.   s    M*(4+<+<*=Q?F#D	?I 1>VM?!,8Vl !z "3 4A/ B" #/ 0& '3^3Ml^ \  $~~. /	gxv	 

  ( )	 
 		. w/v.

5

5
r$   subjectr9   r:   c                 t    [        S5      nU R                   SU R                   S3US'   XS'   X%S'   U(       a  [        US5      nUR	                  U5        [        US5      nUR	                  U5        U R                  XQ5      $ ! [         a'  nU R                  R                  S	U 3S
S9   SnAgSnAff = f)z
Send email using SMTP

Args:
    recipient_email: Recipient email address
    subject: Email subject
    html_content: HTML email content
    text_content: Plain text email content (optional)
    
Returns:
    True if successful, False otherwise
r+   r,   r-   r.   r/   r0   r3   r4   zError sending email: Texc_infoNF)	r   r   r   r   r6   
_send_smtp	Exceptionr   error)	r    r%   r?   r9   r:   r7   r;   r<   es	            r!   
send_emailEmailSender.send_email   s    	.C!^^,Bt/@/@.ACCK'I$	N  w7

5!\62EJJu ??388 	KK 5aS9DI	s   BB 
B7B22B7driver_namedriver_emaildriver_phoneotpc                 6   [        S5      nU R                   SU R                   S3US'   XS'   SUS'   SU S	U S
U SU SU R                   S3nSU SU SU SU S3	n[        US5      n	[        US5      n
UR	                  U	5        UR	                  U
5        U$ )a"  
Create email template for driver information with OTP

Args:
    recipient_email: Recipient email address
    driver_name: Driver name
    driver_email: Driver email address
    driver_phone: Driver phone number
    otp: One-time password/OTP
    
Returns:
    MIMEMultipart email message
r+   r,   r-   r.   r/   z$Your Driver Information - Troy Ridesr0   uF  
        <!DOCTYPE html>
        <html>
        <head>
            <meta charset="UTF-8">
            <style>
                body {
                    font-family: Arial, sans-serif;
                    line-height: 1.6;
                    color: #333;
                    max-width: 600px;
                    margin: 0 auto;
                    padding: 20px;
                }
                .container {
                    background-color: #f9f9f9;
                    border-radius: 10px;
                    padding: 30px;
                    margin: 20px 0;
                }
                .header {
                    background-color: #2c3e50;
                    color: white;
                    padding: 20px;
                    border-radius: 10px 10px 0 0;
                    text-align: center;
                }
                .header h1 {
                    margin: 0;
                    font-size: 24px;
                }
                .content {
                    background-color: white;
                    padding: 30px;
                    border-radius: 0 0 10px 10px;
                }
                .driver-info-box {
                    background-color: #ecf0f1;
                    padding: 20px;
                    border-radius: 8px;
                    margin: 20px 0;
                    border-left: 4px solid #3498db;
                }
                .driver-info-item {
                    margin: 10px 0;
                    padding: 10px;
                    background-color: white;
                    border-radius: 5px;
                }
                .driver-info-label {
                    font-weight: bold;
                    color: #2c3e50;
                    display: inline-block;
                    width: 120px;
                }
                .driver-info-value {
                    color: #333;
                }
                .otp-box {
                    background-color: #3498db;
                    color: white;
                    padding: 25px;
                    border-radius: 8px;
                    text-align: center;
                    margin: 25px 0;
                }
                .otp-label {
                    font-size: 14px;
                    margin-bottom: 10px;
                    opacity: 0.9;
                }
                .otp-code {
                    font-size: 42px;
                    font-weight: bold;
                    letter-spacing: 8px;
                    margin: 15px 0;
                    font-family: 'Courier New', monospace;
                }
                .info-note {
                    background-color: #fff3cd;
                    border-left: 4px solid #ffc107;
                    padding: 15px;
                    border-radius: 5px;
                    margin: 20px 0;
                    color: #856404;
                }
                .footer {
                    text-align: center;
                    margin-top: 30px;
                    padding-top: 20px;
                    border-top: 1px solid #ddd;
                    color: #777;
                    font-size: 12px;
                }
            </style>
        </head>
        <body>
            <div class="container">
                <div class="header">
                    <h1>🚗 Troy Rides</h1>
                </div>
                <div class="content">
                    <p>Hello,</p>
                    
                    <p>Your ride has been assigned! Here are your driver details:</p>
                    
                    <div class="driver-info-box">
                        <h3 style="margin-top: 0; color: #2c3e50;">Driver Information</h3>
                        
                        <div class="driver-info-item">
                            <span class="driver-info-label">Name:</span>
                            <span class="driver-info-value">z</span>
                        </div>
                        
                        <div class="driver-info-item">
                            <span class="driver-info-label">Email:</span>
                            <span class="driver-info-value">z</span>
                        </div>
                        
                        <div class="driver-info-item">
                            <span class="driver-info-label">Phone:</span>
                            <span class="driver-info-value">a  </span>
                        </div>
                    </div>
                    
                    <div class="otp-box">
                        <div class="otp-label">Your One-Time Password (OTP)</div>
                        <div class="otp-code">u  </div>
                        <div style="font-size: 12px; margin-top: 10px; opacity: 0.9;">
                            Please provide this OTP to your driver to verify your ride
                        </div>
                    </div>
                    
                    <div class="info-note">
                        <strong>⚠️ Important:</strong> Please keep your OTP confidential and only share it with your assigned driver when they arrive.
                    </div>
                    
                    <p>Your driver will contact you shortly. If you have any questions or concerns, please don't hesitate to contact us.</p>
                    
                    <p>Best regards,<br>
                    <strong>Troy Rides Team</strong></p>
                </div>
                <div class="footer">
                    <p>This is an automated email. Please do not reply to this message.</p>
                    <p>&copy; r2   z
        Troy Rides - Driver Information
        
        Hello,
        
        Your ride has been assigned! Here are your driver details:
        
        Driver Information:
        -------------------
        Name: z
        Email: z
        Phone: z0
        
        Your One-Time Password (OTP): a  
        
        Please provide this OTP to your driver to verify your ride.
        
        Important: Please keep your OTP confidential and only share it with your assigned driver when they arrive.
        
        Your driver will contact you shortly. If you have any questions or concerns, please don't hesitate to contact us.
        
        Best regards,
        Troy Rides Team
        
        ---
        This is an automated email. Please do not reply to this message.
        r3   r4   r5   )r    r%   rI   rJ   rK   rL   r7   r9   r:   r;   r<   s              r!   create_driver_info_email$EmailSender.create_driver_info_email  s     M*(4+<+<*=Q?F#D	?Io=^ >IM J=
 >JN K=
 >JN K/ 03e 4"  $~~. /	aUp	 m ~ ~ ''*e ,	: w/v.

5

5
r$   c                      U R                  XX45      nU R                  XQ5      $ ! [         a'  nU R                  R	                  SU 3SS9   SnAgSnAff = f)z
Send fare estimate email

Args:
    recipient_email: Recipient email address
    estimate_fare: Estimated fare amount
    payment_link: Payment link URL
    customer_name: Optional customer name
    
Returns:
    True if successful, False otherwise
z#Error sending fare estimate email: TrA   NF)r=   rC   rD   r   rE   )r    r%   r&   r'   r(   r7   rF   s          r!   send_fare_estimateEmailSender.send_fare_estimate  s\    	11/R^nC??388 	KK CA3GRVW	s   "% 
AAAc                      U R                  XX4U5      nU R                  Xa5      $ ! [         a'  nU R                  R	                  SU 3SS9   SnAgSnAff = f)a  
Send driver information email with OTP

Args:
    recipient_email: Recipient email address
    driver_name: Driver name
    driver_email: Driver email address
    driver_phone: Driver phone number
    otp: One-time password/OTP
    
Returns:
    True if successful, False otherwise
z!Error sending driver info email: TrA   NF)rN   rC   rD   r   rE   )r    r%   rI   rJ   rK   rL   r7   rF   s           r!   send_driver_infoEmailSender.send_driver_info  s^    	//ljmnC??388 	KK A!EPTU	s   #& 
AAAr7   c                 D    U R                   S:X  a,  [        R                  " U R                  U R                  5      nO;[        R
                  " U R                  U R                  5      nUR                  5         UR                  U R                  U R                  5        UR                  5       nUR                  U R                  X$5        UR                  5         U R                  R                  SU 35        g! [        R                    a(  nU R                  R#                  SU 35         SnAgSnAf[        R$                   a(  nU R                  R#                  SU 35         SnAgSnAf[&         a'  nU R                  R#                  SU 3SS	9   SnAgSnAff = f)
z
Send email via SMTP

Args:
    msg: Email message
    recipient_email: Recipient email address
    
Returns:
    True if successful, False otherwise
sslzEmail sent successfully to TzSMTP Authentication failed: NFzSMTP error: zError sending email via SMTP: rA   )r   smtplibSMTP_SSLr   r   SMTPstarttlsloginr   r   	as_stringsendmailr   quitr   infoSMTPAuthenticationErrorrE   SMTPExceptionrD   )r    r7   r%   servertextrF   s         r!   rC   EmailSender._send_smtp  s:   	%' ))$))TYY? !dii;! LL6 ==?DOOD--EKKMKK:?:KLM.. 	KK <QC@A$$ 	KKQC01 	KK >qcBTR	s0   C7C: :FD11FE++F8FF)r   r   r   r   r   r   r   r   )zsmtp.gmail.comi  NNrW   Nr   )N)r   
__module____qualname____firstlineno____doc__strintr"   r   r   r=   boolrG   rN   rQ   rT   rC   __static_attributes__ r$   r!   r	   r	      s   * . !%!%#(%)".CCC C 	C
 !C  #C  CB CGp# pc pad p2:3-pKXpf 26"# " "3 "!)#":>"HQ Q# Q]` Q/2Q9<QANQh :># c Y\ )1#BF* # UX &)038<,'m 'c 'd 'r$   r	   )rX   email.mime.textr   email.mime.multipartr   email.mime.baser   emailr   r   typingr   r   r	   rn   r$   r!   <module>rt      s)     $ . $    	^ ^r$   