improve email

This commit is contained in:
CHIEFSOFT\ameye
2025-09-05 19:29:28 -04:00
parent 399ccc25ee
commit 78dd6fec6e
5 changed files with 208 additions and 16 deletions
+86
View File
@@ -132,6 +132,92 @@ class BaseService:
server.quit() # Close the connection
def send_verify_signup_mail(signup_email, pending_uid, pending_id, firstname, lastname):
pending_member = {
"email": signup_email,
"pending_uid": pending_uid,
"first_name": firstname,
"last_name": lastname,
"pending_id": pending_id,
}
jwt_part = jwt.encode(
{"user": pending_member, 'exp': datetime.datetime.utcnow() + datetime.timedelta(minutes=3330)},
BaseService.JWT_SECRET_KEY, algorithm='HS256'
)
panel_url = panel_url = BaseService.THIS_SITE_URL # "https://qa-panel.mermsemr.com"
link_url = str(panel_url) + '/csignup/' + jwt_part
msg_body = f"""
Hello {firstname},
You received this message for account verification
Follow the link:{link_url}
For any Support
Reach Out
support@mermsemr.com
"""
sender_email = BaseService.SEND_EMAIL_FROM
sender_password = BaseService.SEND_EMAIL_PASS
receiver_email = signup_email
subject = "Verify your MERMS(AI) Account Setup"
body = msg_body
html_body = f"""\
<html>
<head></head>
<body style="font-size:14px;line-height:1.5;">
<table width="550px" border="0" cellpadding="3" cellspacing="3" background-color="#F0F8FF" style="font-size:16px">
<tr>
<td style="text-align:center">
<img style="width:150px; height:auto;" src="mermsemr.com/images/logo-pink.png" />
</td>
</tr>
<tr>
<td>
Hello <b>{firstname}!</b>
</td>
</tr>
<tr>
<td>
You have received this message for your account verification<br>
</td>
</tr>
<tr>
<td>
Follow the link: <a href="{link_url}">link</a> to complete the verification process.<br>
</td>
</tr>
</table>
</body>
</html>
"""
msg = MIMEMultipart()
msg['Subject'] = subject
msg['From'] = sender_email
msg['To'] = receiver_email
msg.attach(MIMEText(html_body, 'html')) # or 'html' for HTML content
try:
# For Gmail, use 'smtp.gmail.com' and port 587 (TLS) or 465 (SSL)
# For other providers, consult their documentation for SMTP server and port
server = smtplib.SMTP('smtp.gmail.com', 587)
# server.starttls() # Enable TLS encryption
server.login(sender_email, sender_password)
server.sendmail(sender_email, receiver_email, msg.as_string())
print("Email sent successfully!")
except Exception as e:
print(f"Error sending email: {e}")
logger.error(f"Error sending email: {e}")
finally:
server.quit() # Close the connection
@classmethod
def validate_data(cls, data, schema):
"""