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:
+8
-2
@@ -202,6 +202,8 @@ class EmailForwarder:
|
|||||||
# Send via SMTP
|
# Send via SMTP
|
||||||
self.throttle.wait_if_needed()
|
self.throttle.wait_if_needed()
|
||||||
|
|
||||||
|
server = None
|
||||||
|
try:
|
||||||
if self.smtp_use_tls:
|
if self.smtp_use_tls:
|
||||||
server = smtplib.SMTP(self.smtp_host, self.smtp_port)
|
server = smtplib.SMTP(self.smtp_host, self.smtp_port)
|
||||||
server.starttls()
|
server.starttls()
|
||||||
@@ -210,10 +212,15 @@ class EmailForwarder:
|
|||||||
|
|
||||||
server.login(self.smtp_user, self.smtp_password)
|
server.login(self.smtp_user, self.smtp_password)
|
||||||
server.send_message(forward_msg)
|
server.send_message(forward_msg)
|
||||||
server.quit()
|
|
||||||
|
|
||||||
logger.info(f"Successfully forwarded email to {self.gmail_destination}")
|
logger.info(f"Successfully forwarded email to {self.gmail_destination}")
|
||||||
return True
|
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")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user