Kaynağa Gözat

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

Martino 3 yıl önce
ebeveyn
işleme
850295f476
1 değiştirilmiş dosya ile 4 ekleme ve 3 silme
  1. 4 3
      redmail/email/sender.py

+ 4 - 3
redmail/email/sender.py

@@ -440,8 +440,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"
@@ -555,4 +556,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