kootenpv / yagmail

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

ValueError: stat: path too long for Windows #44

Closed Dylan-Chapman closed 5 years ago

Dylan-Chapman commented 8 years ago

I'm sending a long-ish email (HTML) and am receiving this error when sending on Windows. I'm assuming this happens because of Windows file path limit and because, as the README says, the contents argument 'will try to see if the content (string) can be read as a file locally, e.g. '/path/to/image.png''.

The last few entries from the traceback are

...
  File "[path]\yagmail\yagmail.py", line 98, in send
    msg = self._prepare_message(addresses, subject, contents, attachments, headers)
  File "[path]\yagmail\yagmail.py", line 217, in _prepare_message
    has_included_images, content_objects = self._prepare_contents(contents)
  File "[path]\yagmail\yagmail.py", line 276, in _prepare_contents
    content_object = self._get_mime_object(content)
  File "[path]\yagmail\yagmail.py", line 347, in _get_mime_object
    if os.path.isfile(content_string) and not is_raw:
  File "[path]\lib\genericpath.py", line 30, in isfile
    st = os.stat(path)
ValueError: stat: path too long for Windows

Is there a way to get around this?

kootenpv commented 8 years ago

My apologies, this is unfortunate.

In your case, you can safeguard your contents with "raw" as in:

yag.send(contents=yagmail.raw(html_text))

But then the problem is that it is not html. Wow, this is the first time it is not clear for me how this should be implemented. Let me get back to you on that.

Are you sending scraped contents or a file? If a file, you could of course send the file directly, that would be the best workaround possible at the moment.

Dylan-Chapman commented 8 years ago

Thankfully I'm just sending an HTML list (scraped contents), so I can convert it to line-by-line text and send it with raw.

Glancing at the code, I'm not sure of a solution off the top of my head either. Unfortunately I'm still in the midst of learning Python.

rajat-np commented 5 years ago

@kootenpv I tried using yagmail.raw() , and it's working. :)