Add new alert architecture
This commit is contained in:
@@ -276,14 +276,26 @@ class EmailService:
|
||||
|
||||
# Test SMTP connection
|
||||
if self.smtp_ssl:
|
||||
# Use implicit TLS/SSL connection (port 465 typically)
|
||||
server = aiosmtplib.SMTP(hostname=self.smtp_host, port=self.smtp_port, use_tls=True)
|
||||
await server.connect()
|
||||
# No need for starttls() when using implicit TLS
|
||||
else:
|
||||
# Use plain connection, optionally upgrade with STARTTLS
|
||||
server = aiosmtplib.SMTP(hostname=self.smtp_host, port=self.smtp_port)
|
||||
|
||||
await server.connect()
|
||||
|
||||
if self.smtp_tls:
|
||||
await server.starttls()
|
||||
await server.connect()
|
||||
|
||||
if self.smtp_tls:
|
||||
# Try STARTTLS, but handle case where connection is already secure
|
||||
try:
|
||||
await server.starttls()
|
||||
except Exception as starttls_error:
|
||||
# If STARTTLS fails because connection is already using TLS, that's okay
|
||||
if "already using TLS" in str(starttls_error) or "already secure" in str(starttls_error):
|
||||
logger.debug("SMTP connection already secure, skipping STARTTLS")
|
||||
else:
|
||||
# Re-raise other STARTTLS errors
|
||||
raise starttls_error
|
||||
|
||||
await server.login(self.smtp_user, self.smtp_password)
|
||||
await server.quit()
|
||||
|
||||
Reference in New Issue
Block a user