Update.:
This commit is contained in:
parent
d957968e6f
commit
f2735b19e7
11
rbox/mail.py
11
rbox/mail.py
@ -79,7 +79,8 @@ class EmailService:
|
||||
msg.attach(html_part)
|
||||
|
||||
try:
|
||||
if settings.SMTP_PORT == 465:
|
||||
# Use implicit TLS for port 465 or when SMTP_USE_TLS is True
|
||||
if settings.SMTP_PORT == 465 or settings.SMTP_USE_TLS:
|
||||
async with aiosmtplib.SMTP(
|
||||
hostname=settings.SMTP_HOST,
|
||||
port=settings.SMTP_PORT,
|
||||
@ -90,11 +91,19 @@ class EmailService:
|
||||
await smtp.send_message(msg)
|
||||
print(f"Email sent to {task.to_email}")
|
||||
else:
|
||||
# Use STARTTLS for other ports
|
||||
async with aiosmtplib.SMTP(
|
||||
hostname=settings.SMTP_HOST,
|
||||
port=settings.SMTP_PORT,
|
||||
) as smtp:
|
||||
try:
|
||||
await smtp.starttls()
|
||||
except Exception as tls_error:
|
||||
if "already using" in str(tls_error).lower() or "tls" in str(tls_error).lower():
|
||||
# Connection is already using TLS, proceed without starttls
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
await smtp.login(settings.SMTP_USERNAME, settings.SMTP_PASSWORD)
|
||||
await smtp.send_message(msg)
|
||||
print(f"Email sent to {task.to_email}")
|
||||
|
||||
Loading…
Reference in New Issue
Block a user