kootenpv / yagmail

Send email in Python conveniently for gmail using yagmail
MIT License
2.66k stars 265 forks source link

Error report while start my application #253

Open ThrowSyntaxError opened 2 years ago

ThrowSyntaxError commented 2 years ago

here is some error message: Exception ignored in: <function SMTP.del at 0x7f60bed18430>

Traceback (most recent call last):
  File "/root/anaconda3/envs/yixing_39/lib/python3.8/site-packages/yagmail/sender.py", line 261, in __del__
  File "/root/anaconda3/envs/yixing_39/lib/python3.8/site-packages/yagmail/sender.py", line 203, in close
TypeError: catching classes that do not inherit from BaseException is not allowed

description: I'm gonna test the function of sending email by using yagmail module in my app,but when I running my project the above problem occurred. dose it exist an error in source code? or just my fault? How should I solve this problem?

here is the code for the corresponding location above:

 def close(self):
        """ Close the connection to the SMTP server """
        self.is_closed = True
        try:
            self.smtp.quit()
        except (TypeError, AttributeError, smtplib.SMTPServerDisconnected):  # line 203
            pass
kootenpv commented 2 years ago

How are you using yagmail

ThrowSyntaxError commented 2 years ago

你如何使用亚格邮件

I smply use it just like this

 class mailManager:
     def __init__(self):
         self.User = 'sender@mail.com'
         self.PassWord = '**********'
         self.SMTPClient = yagmail.SMTP(
             host='smtp.EmailServer.com',
             user=self.User,
             password=self.PassWord,
             port=465
         )

     def sendMail(self, receiver, subject, text):
         try:
             self.SMTPClient.send(receiver, subject, text)
             print("Successfully sending e-mail!")
         except Exception:
             print("Error while sending e-mail:", Exception)
kootenpv commented 2 years ago

Try creating the smtp client right before sending all the time

ThrowSyntaxError commented 2 years ago

Try creating the smtp client right before sending all the time

Acturally I just create a new mialManager instance in file app.py and not using sendMail function yet. I've switched to smptlib module in my app temporarily, but I still wanna figure it out. I notice that sometimes you need create a connection by using smtplib.SMTP_SSL() instead of smtplib.SMTP() in smtplib module, is this one of the possible reasons?