kootenpv / yagmail

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

Can't send string longer than 2^15 - 1 letters #100

Open vavanade opened 6 years ago

vavanade commented 6 years ago

If I try to send contents string of length 2^15 (32768) characters or longer the os module isfile check fails. Example: import yagmail

yag = yagmail.SMTP(user="coolusername", password="v3rys3cr3tp@ssw0rd")
yag.send(to="foo@bar.foobar", subject="I will be sent :)", contents="a"*32767)
yag.send(to="foo@bar.foobar", subject="I will fail :(", contents="a"*32768)

output:

{}

Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "C:\Users\myusername\AppData\Local\Programs\Python\Python36\lib\site-packages\yagmail\sender.py", 
line 124, in send
    msg = self._prepare_message(addresses, subject, contents, attachments, headers)
  File "C:\Users\myusername\AppData\Local\Programs\Python\Python36\lib\site-packages\yagmail\sender.py", 
line 250, in _prepare_message
    has_included_images, content_objects = self._prepare_contents(contents)
  File "C:\Users\myusername\AppData\Local\Programs\Python\Python36\lib\site-packages\yagmail\sender.py", 
line 323, in _prepare_contents
    content_object = self._get_mime_object(content)
  File "C:\Users\myusername\AppData\Local\Programs\Python\Python36\lib\site-packages\yagmail\sender.py", line 399, in _get_mime_object
    if os.path.isfile(content_string) and not is_raw:
  File "C:\Users\myusername\AppData\Local\Programs\Python\Python36\lib\genericpath.py", line 30, in isfile
    st = os.stat(path)
ValueError: stat: path too long for Windows
vavanade commented 6 years ago

One can always do yag.send(to="foo@bar.foobar", subject="I will be sent :)", contents=["a"*32767]*n). I posted it just so everyone is aware of this limit.