You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to get all enclosed files (doc, pdf, etc.) from an email. In order to reach those files when inside an enclosed message, I'm using a recursive function:
...
for MailItem in FilteredMail:
ReadAttachments(MailItem)
def ReadAttachments(MailItem)
for Attachment in MailItem.attachments
if hasattr(Attachment, 'item'): #attachment is a message
ReadAttachments(Atachment.item)
else: #attachment is a file (e.g. PDF)
print Attachment.name + ':' + Attachment.size
<do whatever with Attachment.content>
This works OK for regular emails, but fails for files inside other messages (Email1 > contains Email 2 > contains file.pdf). It's curious that in these cases Attachment.name and Attachment.size are displayed properly, but any action with Attachment.content results in a "FileAttachment must have an account" error.
Thanks in advance!!
The text was updated successfully, but these errors were encountered:
Worked like a charm. Thanks a lot!! The resulting code below for reference.
...
for MailItem in FilteredMail:
ReadAttachments(MailItem, MailItem)
def ReadAttachments(MailItem, RootParent)
for Attachment in MailItem.attachments
Attachment.parent_item = RootParent
if hasattr(Attachment, 'item'): #attachment is a message
ReadAttachments(Atachment.item, RootParent)
else: #attachment is a file (e.g. PDF)
print Attachment.name + ':' + Attachment.size
<do whatever with Attachment.content>
I'm trying to get all enclosed files (doc, pdf, etc.) from an email. In order to reach those files when inside an enclosed message, I'm using a recursive function:
This works OK for regular emails, but fails for files inside other messages (Email1 > contains Email 2 > contains file.pdf). It's curious that in these cases Attachment.name and Attachment.size are displayed properly, but any action with Attachment.content results in a "FileAttachment must have an account" error.
Thanks in advance!!
The text was updated successfully, but these errors were encountered: