Forráskód Böngészése

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

Martino 3 éve
szülő
commit
a5d679f3e4
1 módosított fájl, 4 hozzáadás és 3 törlés
  1. 4 3
      redmail/email/sender.py

+ 4 - 3
redmail/email/sender.py

@@ -452,8 +452,9 @@ class EmailSender:
 
     def close(self):
         "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:
         "Connect and get the SMTP Server"
@@ -567,4 +568,4 @@ class EmailSender:
     @user_name.setter
     def user_name(self, user):
         warnings.warn("Attribute user_name was renamed as username. Please use username instead.", FutureWarning)
-        self.username = user
+        self.username = user