kootenpv / yagmail

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

Exception AttributeError: "SMTP instance has no attribute 'is_closed'" #52

Closed davidhuser closed 8 years ago

davidhuser commented 8 years ago

I'm trying to send a mail but get the following error:

yag = yagmail.SMTP(conf['sender_username'], conf['sender_password'])
  File "/usr/local/lib/python2.7/dist-packages/yagmail/yagmail.py", line 54, in __init__
    self.user, self.useralias = self._make_addr_alias_user(user)
  File "/usr/local/lib/python2.7/dist-packages/yagmail/yagmail.py", line 305, in _make_addr_alias_user
    raise YagAddressError
yagmail.error.YagAddressError
Exception AttributeError: "SMTP instance has no attribute 'is_closed'" in <bound method SMTP.__del__ of <yagmail.yagmail.SMTP instance at 0x7fb99cb8ccf8>> ignored

Where my code looks like this, username and password are read from a JSON file and successfully printed.

contents='test \n test'
with yagmail.SMTP(conf['sender_username'], conf['sender_password']) as yag:
    yag.send(to=['testuser@mail.com"], subject='testmail', content=contents)
kootenpv commented 8 years ago

Please try updating :) I think it should have been solved as of https://github.com/kootenpv/yagmail/commit/0c51becf76a7107b4295153c5ff41e8ecc5d2f84#diff-bd3f77edb783f45081ab58b074bee760R450

You can upgrade by using: pip install -U yagmail

davidhuser commented 8 years ago

Thanks for the quick response! Unfortunately it still raises the same Error.

$ pip show yagmail
---
Name: yagmail
Version: 0.5.147
Location: /usr/local/lib/python2.7/dist-packages
Requires: keyring

Is this the version with the fix?

davidhuser commented 8 years ago

My version includes the commit from above. Running it from the commandline is fine, the Error is raised in this line according to the error: https://github.com/kootenpv/yagmail/blob/master/yagmail/yagmail.py#L305

kootenpv commented 8 years ago

The last number of the version is the commit number, so you can always verify yourself :)

The line number you're "quoting" shows that there is a problem with your "from" address. Are you sure it is a string or dict and not a list (whereas you can have a list for to, not for from)?

davidhuser commented 8 years ago

Thanks! I casted the sender username to a string using str(username) and now it works.

kootenpv commented 8 years ago

Was it bytes? Then I should probably make sure it checks for that as well...

davidhuser commented 8 years ago

It was Unicode. Tell me if you need to know something else.

print type(conf['username'))
<type 'unicode'>