mail_folder.get_message(object_id=... returns the original mail and not the attachment
If you have an attachment that is an attached mail (attachment_type=='item'), and if you try to get the message with mail_folter.get_message(object_id=attachemnent.attachment_id) it returns the container mail and not the attached mail
if msg.has_attachments:
for att in msg.attachments:
if not att.is_inline and att.attachment_type == 'item':
print(att)
att_dl = folder.get_message(object_id=att.attachment_id) # Not getting the attached mail
You can do it but I must admit it's a little obscure.
if msg.has_attachments:
for att in msg.attachments:
if not att.is_inline and att.attachment_type == 'item':
msg.attachments.save_as_eml(att, to_path='my path')
Thanks for the answer, but it is not exactly the behaviour I am looking for. I don't want to save the mail, I want the read it and analyse it.
The Ms Graph Api only returns data from attached messages as an "eml" file with it's structure.
It's quite difficult to re-construct an O365 Message object from a 'eml' file format.
Yes, indeed, but what I was looking was the ability to call something like :
https://graph.microsoft.com/v1.0/users/{user_id}/messages/{messages_id}/attachments/{attachement_id}/?$expand=microsoft.graph.itemattachment/item
Are you sure this works on message attachments?
did you guys find a solution for this request? I am trying to find out wether 0365 lib supports retrieving attachment of type message
my fallback approach would be to call the corresponding graph api endpoint directly.. but as its messy to parse the result i would rather use 0365 lib
You can retrieve it as shown in the example code I posted. But for the moment the only thing supported is to save the content to disk. You can (if you know how) read that into memory and work with that data
hello, did you find a solution to this ? with EWS it was easy to process such items, but migrating to MS Graph I'm stuck with this
for what it's worth, here is my quick workaround which creates a message I can process:
# email is my original email which has a single attachment which is an item with another email
url = email.attachments.build_url(email.attachments._endpoints.get('get_mime').format(id=email.object_id, ida=attachments[0].attachment_id))
# as pdelporte suggestion and ms graph doc
response = email.con.get(f'{url.removesuffix("$value")}?$expand=microsoft.graph.itemattachment/item').json()
#
attachment = account.mailbox(resource=my_resource).message_constructor(parent=account.mailbox(resource=my_resource), **{account.mailbox(resource=my_resource)._cloud_data_key: response.get('item', [])})
Here attachment is a Message which can be processed as a standard Message sent with get_messages()