How to read the messages from an Office 365 mailbox / archive using Powershell

Tagged: ,

This topic contains 3 replies, has 3 voices, and was last updated by Profile photo of Ben Penney Ben Penney 1 year, 1 month ago.

  • Author
    Posts
  • #19272
    Profile photo of Eric Snyder
    Eric Snyder
    Participant

    I'm attempting to read the messages from my mailbox using PowerShell 4.

    I can open my mailbox, and I can enumerate the folders.

    I can't seem to find a way to read messages from the folders, and wonder if anyone has some code they would like to recommend for doing so with Office 365 latest as of this date.

    I would like to be able to read messages from my inbox as well as my online archive (which I have not found a way to access as of yet), enumerate them, and be able to output their content (subject, from addresses, message, etc)

    -thanks in advance
    -e

  • #19314
    Profile photo of Don Jones
    Don Jones
    Keymaster

    As far as I'm aware (and I could be wrong), the Exchange commands don't include anything for reading content from mailbox items. That would include O365.

    However, O365 supports the IMAP protocol. You could certainly use that to access the contents of a mailbox, but there are no native command sfor doing so. /n software's PowerCmdlets may offer an IMAP option.

    You might also look at http://blog.pluralsight.com/powershell-to-read-emails, which uses PowerShell *and Outlook* to access mailbox contents.

  • #19342
    Profile photo of Eric Snyder
    Eric Snyder
    Participant

    Upon changing my approach from remoting to the Office 365 server to looking at Exchange functionality, I discovered the EWS Dll.

    It appears that one can use that and obtain just about whatever one wants via the web. I'm sure it is throttled, but should work.

    Some links I've found so far:

    Reading headers.. this one is just a few inches from what I need, because it already opens the item. Just a matter of looking at the $item.body
    http://gallery.technet.microsoft.com/scriptcenter/How-to-export-Email-7f63a63c

    Autodiscover:
    http://mikepfeiffer.net/2011/08/testing-exchange-autodiscover-with-powershell-and-the-ews-managed-api/

    Get messages (use with caution — don't know the site yet)
    http://poshcode.org/2520

    The trick was discovering that Exchange Office 365 could be accessed with the Microsoft.Exchange.Webservices dll, and then
    binging for : "powershell microsoft.exchange.webservices.dll" ..

    I'll remember that algorithm in the future, since I'm a C#/>net developer. If searches for what you want to do like "powershell read email" don't turn up anything, look up how one would do it in C#, and find the object name, and search for that.

    I appreciate this community and all your help.

    Powershell on.

    -thanks
    -e

  • #31579
    Profile photo of Ben Penney
    Ben Penney
    Participant

    Here is some PowerShell code to read emails from O365 with only the .dll file from the EWS required.

    Includes reading the body of the email,

You must be logged in to reply to this topic.