o
    "i_                     @   sv   d dl Z d dlmZ d dlmZ d dlmZ d dlZee	Z
dedededefd	d
ZdedededefddZdS )    N)MIMEText)MIMEMultipart)settingsto_emailsubjecthtml_contentreturnc              
      s   z?t d}||d< tj dtj d|d< | |d< t|d}|| tj|tjtj	tj
tjdd	I d
H  td|   W dS  ty` } ztd|  dt|  W Y d
}~dS d
}~ww )zSend an email using SMTPalternativeSubjectz <>FromTohtmlT)hostnameportusernamepassword	start_tlsNzEmail sent successfully to zFailed to send email to z: F)r   r   SMTP_FROM_NAME	SMTP_FROMr   attach
aiosmtplibsend	SMTP_HOST	SMTP_PORT	SMTP_USERSMTP_PASSWORDloggerinfo	Exceptionerrorstr)r   r   r   message	html_parte r%   C/lsinfo/ai/hellotax_ai/base_platform/app/services/platform/email.py
send_email
   s.   

	r'   emailtokennamec                    s>   t j d| }d| d| d| d}t| d|dI dH S )	zSend email verification linkz/verify-email?token=u  
    <!DOCTYPE html>
    <html>
    <head>
        <meta charset="utf-8">
        <style>
            body {
                font-family: Arial, sans-serif;
                line-height: 1.6;
                color: #333;
            }
            .container {
                max-width: 600px;
                margin: 0 auto;
                padding: 20px;
            }
            .header {
                background-color: #4CAF50;
                color: white;
                padding: 20px;
                text-align: center;
                border-radius: 5px 5px 0 0;
            }
            .content {
                background-color: #f9f9f9;
                padding: 30px;
                border-radius: 0 0 5px 5px;
            }
            .button {
                display: inline-block;
                padding: 12px 30px;
                background-color: #4CAF50;
                color: white;
                text-decoration: none;
                border-radius: 5px;
                margin: 20px 0;
            }
            .footer {
                text-align: center;
                margin-top: 20px;
                color: #666;
                font-size: 12px;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <div class="header">
                <h1>欢迎加入 HelloTax AI</h1>
            </div>
            <div class="content">
                <p>你好 u   ,</p>
                <p>感谢您注册 HelloTax AI！请点击下面的按钮验证您的邮箱地址：</p>
                <div style="text-align: center;">
                    <a href="u   " class="button">验证邮箱</a>
                </div>
                <p>或者复制以下链接到浏览器：</p>
                <p style="word-break: break-all; color: #666;">uB  </p>
                <p>此链接将在24小时后过期。</p>
                <p>如果您没有注册账户，请忽略此邮件。</p>
            </div>
            <div class="footer">
                <p>&copy; 2026 HelloTax AI. All rights reserved.</p>
            </div>
        </div>
    </body>
    </html>
    u    验证您的邮箱 - HelloTax AI)r   r   r   N)r   FRONTEND_URLr'   )r(   r)   r*   verification_urlr   r%   r%   r&   send_verification_email)   s   369Er-   )r   email.mime.textr   email.mime.multipartr   
app.configr   logging	getLogger__name__r   r!   boolr'   r-   r%   r%   r%   r&   <module>   s    
