瀏覽代碼

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

Martino 3 年之前
父節點
當前提交
850295f476
共有 1 個文件被更改,包括 4 次插入3 次删除
  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