python-o365
python-o365 copied to clipboard
AttributeError for sending mail with binary attachment
If I understood correctly, I can attach a binary (in my case of a PDF) to a message as follows:
message.attachments.add(attachments=[(bytes, fileName)])
However, I get the following error when trying to send the mail:
File "/opt/venv/lib/python3.9/site-packages/O365/message.py", line 697, in send
self.save_draft()
File "/opt/venv/lib/python3.9/site-packages/O365/message.py", line 953, in save_draft self.attachments._update_attachments_to_cloud()
File "/opt/venv/lib/python3.9/site-packages/O365/utils/attachment.py", line 478, in _update_attachments_to_cloud file_size = attachment.attachment.stat().st_size
AttributeError: 'NoneType' object has no attribute 'stat'
I have already looked at the code and cannot understand what exactly I am doing wrong. Is it possible that this is broken or what am I doing wrong?
Thanks in advance
The object should be a BytesIO object.
You can add one like this:
attachment = (bytesio_object, 'attachment_name')
message.attachments.add([attachment])