Преглед на файлове

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

Martino преди 3 години
родител
ревизия
a5d679f3e4
променени са 1 файла, в които са добавени 4 реда и са изтрити 3 реда
  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