Răsfoiți Sursa

Call on close() on fresh sender raises attribute error as the connection is None

Martino 3 ani în urmă
părinte
comite
a5d679f3e4
1 a modificat fișierele cu 4 adăugiri și 3 ștergeri
  1. 4 3
      redmail/email/sender.py

+ 4 - 3
redmail/email/sender.py

@@ -452,8 +452,9 @@ class EmailSender:
 
 
     def close(self):
     def close(self):
         "Close (quit) the connection"
         "Close (quit) the connection"
-        self.connection.quit()
-        self.connection = None
+        if self.connection:
+            self.connection.quit()
+            self.connection = None
 
 
     def get_server(self) -> smtplib.SMTP:
     def get_server(self) -> smtplib.SMTP:
         "Connect and get the SMTP Server"
         "Connect and get the SMTP Server"
@@ -567,4 +568,4 @@ class EmailSender:
     @user_name.setter
     @user_name.setter
     def user_name(self, user):
     def user_name(self, user):
         warnings.warn("Attribute user_name was renamed as username. Please use username instead.", FutureWarning)
         warnings.warn("Attribute user_name was renamed as username. Please use username instead.", FutureWarning)
-        self.username = user
+        self.username = user