Fix code review issues: remove duplicate import and improve SMTP cleanup

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-01 12:15:59 +00:00
parent aa9be83758
commit 810ebed3e2
+19 -13
View File
@@ -202,18 +202,25 @@ class EmailForwarder:
# Send via SMTP # Send via SMTP
self.throttle.wait_if_needed() self.throttle.wait_if_needed()
if self.smtp_use_tls: server = None
server = smtplib.SMTP(self.smtp_host, self.smtp_port) try:
server.starttls() if self.smtp_use_tls:
else: server = smtplib.SMTP(self.smtp_host, self.smtp_port)
server = smtplib.SMTP_SSL(self.smtp_host, self.smtp_port) server.starttls()
else:
server.login(self.smtp_user, self.smtp_password) server = smtplib.SMTP_SSL(self.smtp_host, self.smtp_port)
server.send_message(forward_msg)
server.quit() server.login(self.smtp_user, self.smtp_password)
server.send_message(forward_msg)
logger.info(f"Successfully forwarded email to {self.gmail_destination}")
return True logger.info(f"Successfully forwarded email to {self.gmail_destination}")
return True
finally:
if server:
try:
server.quit()
except Exception:
pass # Ignore errors during cleanup
except Exception as e: except Exception as e:
logger.error(f"Error forwarding email: {e}") logger.error(f"Error forwarding email: {e}")
@@ -228,7 +235,6 @@ class EmailForwarder:
try: try:
import http.client import http.client
import json
conn = http.client.HTTPSConnection("api.postmarkapp.com") conn = http.client.HTTPSConnection("api.postmarkapp.com")