Download Outlook Email Attachments Using Microsoft Graph Api In C

0 views
Skip to first unread message

Nicoletta Monjure

unread,
Jan 25, 2024, 6:31:05 PM1/25/24
to preczycite

I'm retrieving Outlook email attachments using msgraph-sdk-phpand noticed that some emails have a .eml attachments. When I get the email attachment by calling /users/user_id/messages/message_id/attachments' I noticed that the response doesn't contain contentBytes key.
for example:

An email attachment is not being recognized as an attachment... I've even tried using the out of the box template available, if it has images, pdf, documents, etc it works fine, if you have an email attached thou it gets ignored, it doesn't even show as an attachment.

download outlook email attachments using microsoft graph api in c


Download Ziphttps://t.co/1PRb1HHKFx



Reply from Microsoft Support Team indicate email are considered "attachment items" not "attachments" (however weird that sounds) and the connector does not recognize them as true attachments to be saved.

A suggestion of an API call is the closes to a solution (see replies for more info). An API call seems not to be able to process email .msg attachments either from what I gather on the reply from the Microsoft Support Team guy.

This bug still exists when using the Get Email (v2) action. But the Microsoft Graph API can be used to get at attached emails inside a message. The Known Issues section of the Office 365 Outlook connector docs gives some instructions on how to get at the appropriate API endpoints. -us/connectors/office365/

If you decide to go straight at the Graph API (e.g. using an Azure Function that gets invoked by your Flow), make sure you consider usage of the ?$expand=attachments parameter to get the nested message's properties included in your root call.

You know that technically, you could do this manually; you could use SharePoint search, find the files, download them, and email them again, or you could do it manually using Outlook mail client. However, the request was for using PowerShell.

Next, you can construct our email and attachments using the matching PDF files you moved to the folder. You can then use Send-MgUserMail to email the requested user or group.

Use this guide if you want to configure the WPO365 LOGIN or WPO365 MICROSOFT GRAPH MAILER to send WordPress emails from one of your Microsoft 365 Exchange Online / Mail enabled accounts using Microsoft Graph instead of SMTP with delegated permissions. Make sure to watch the companion video for this article

Please note To successfully authorize the WordPress application to send emails using Microsoft Graph as a specific user you must have added (and granted admin consent for) at least the delegated API permissions as shown in the previous screenshot.

A premium feature that is enabled by default is support for sending attachments larger than 3 MB from WordPress. To actual send large attachments, the plugin will first create a draft email and then upload one or more (large) attachments. For the plugin to be able to do this, you must update the API Permissions for your App registration in Azure AD and you must add Microsoft Graph > delegated > Mail.ReadWrite permissions (and confirm by clicking Grant admin consent for ...). Alternatively, you can add Microsoft Graph > application > Mail.ReadWrite permissions, but this is not recommended.

You can choose to send emails from a Microsoft 365 Shared Mailbox instead. If you select this option, the Default "From" address (mail account) must be one of the users that has access to the Shared Mailbox. Also, if you configured delegated permissions, you must update the API Permissions for your App registration in Azure AD and you must add Microsoft Graph > delegated > Mail.Send.Shared permissions (and confirm by clicking Grand admin consent for ...). If you expect to send large attachments from a Shared Mailbox then you must also add Microsoft Graph > delegated > Mail.ReadWrite.Shared permissions. If you configured application-level Mail.Send permissions then you will find that you can already sent email as any user from a Shared Mailbox and do not need to add any new permissions.

Yes, there is. When you connect to PowerQuery and pull in the email, you get an "attachments' column. Providing the files are uniform (no necessarily named the same), and the data is in a structure that PQ can interpret, you should be able to expand them to get the content.

So far I've also created a "team site mailbox" with a specific mail adress, so that my customers can forward their data through emails with Excel attchements. Then I've created a POWER QUERY connexion to that mailbox to directly read the data from attachments. So I can refresh the dashboards with the new data directly forwarded by mail.

I'm not sure I follow. If you're using a general mailbox, isn't the email going from that email? The only way I can think of to extract the real sender would be to try and parse the signature lines or something.

Hi Ken, if I get automated email every day with table information, would you suggest to convert this email to text and then do a power query or can I do a power query directly without converting outlook file to text format? Thank you!

I have a bank confirmation email coming to my inbox with table (in a text format) in the middle of the body of the email. On top and bottom it is one paragraph of general information that I do not need.
I connected to exchange however do not see the possibility of stripping the top and bottom paragraphs and combining tables. I tried splitting columns by space, it looks bit "ugly". Not sure what anyone can recommend? Thanks

The only part I don't like about using Power Query is that, it seems if I delete any of the emails from the folder I set up in Outlook, those will be deleted in the spreadsheet, too (which makes perfect sense).

What I have:
step one - connect to a shared mailbox on exchange and filter out emails from last week (this leaves around 1400 emails) or last day (round 350 emails).
I leave only columns with email body, email ID and email send date.
Next I have a function that searches query from step one; uses email ID as input; drills down through email with the specific ID and searches for specific text (using inner.join feature).
Then I have a Second Query; source of Second Query is First Query; Second Query has custom column that calls in The Function.

Ken,
I have an email coming in like shown in the snippet below and I would like to parse the text to be able to create a new row in a table in Excel that has matching columns. Is this something I can do with Power Query? I'm running Office 365 Business Premium with Excel 2016. I looked for the Exchange connection that you mentioned but I don't see it. Is it possible that is due to my license or something? I also tried writing a Flow to achieve the same thing but my flow keeps getting hung up (inconsistently...the "Floors or Suite Numbers" section is the stopping point most of the time) on a couple of pieces of text. It will just stop parsing and run all the remaining text together...hence why I was thinking of cutting out the middle man and using Power Query only! Thoughts? Any help is greatly appreciated!

Hi Ken,
thank you for your detailed explanation
I have a question
what about emails which have HTML table with the same headers,can I combine them using power query?
I tried but the html table display as a set of words when I expand the column of html text.
Regards

What I'm trying to do is auto print attachments from any email that arrive in Folder_X that has an attachment. Once the attachment is printed I need the email to be moved to another folder (Folder_Y). Any email that doesn't have an attachment should't be moved.

We came up with an alternate fix for the problem instead of using VB scripting. We use a system called Mimecast to manage and filter our emails before they the reach our internal exchange system, this is done for security reasons. What we realised is that Mimecast allowed us to send a copy of emails to another mailbox, when a email destined for the mailbox using the VB script is received we are sending a copy to another newly setup mailbox. This now allows us to run 1 inbound mail rule on each mail box meaning I no longer need to run a VB script targeting a folder that already has mail in it. Thanks for your replies.

Sending a message with a large attachment used to be the least worst option when it came to shipping data between people. In the Modern workplace where document and file sharing options are a lot better sending email with a large attachment can tends now to be the worst option especially when it comes to version control, expiration etc. However if you do find yourself with the need to send an email with large attachments (larger then 4MB) and you want to make use of the Microsft Graph API then it requires you use a different method from just sending the message in one post eg -us/graph/outlook-large-attachments?tabs=http

The integration imports email messages from the destination folder in the target mailbox as incidents. If the message contains any attachments, they are uploaded to the War Room as files. If the attachment is an email (item attachment), Cortex XSOAR fetches information about the attached email and downloads all of its attachments (if there are any) as files. To use Fetch incidents, configure a new instance and select the Fetches incidents option in the instance settings.

Downloading email attachments manually is a huge headache for anyone who works on them on a daily basis. Let's say that you are a person or a company that receives hundreds of thousands of emails daily and you want to download one attachment from a specific email recipient / specific date range / specific subject / specific file extension. Just Imagine the hustle and the time you are consuming for that ?

We are aware that there are several Python libraries such as smtplib, imaplib, and pywin32 that we can use to download email attachments, but these won't work if your company uses Okta for Microsoft Account.

df19127ead
Reply all
Reply to author
Forward
0 new messages