Search code examples
c++powershellexchange-serverimap

Need to check the inbox of an Exchange server with C++


I'm working on a project in C++ to backup and restore email on Microsoft Exchange servers, I'm trying to write automated tests for the restore function. Right now I can create test users, databases, and mailboxes, and can send email between users through the Exchange Admin Powershell. However, Exchange doesn't have commandlets to view or delete emails (as far as I can tell). Is there a way to do that with straight Exchange commandlets?

I haven't found a way, so instead I'm looking for an IMAP API that I can add to the project to enable viewing and deleting emails. Free would be ideal, but it can't be licensed with GPL. Is there an IMAP API for C++ that doesn't have GPL? Is there an avenue to programatically view and delete emails I haven't tried yet?

EDIT: Honestly I'm not too fussy on how it gets done, I just need a way to do it. I'm open to any suggestions.


Solution

  • https://technet.microsoft.com/en-us/library/ff459253(v=exchg.150).aspx

    Search-Mailbox can delete messages.

    https://technet.microsoft.com/en-us/library/ee633455(v=exchg.150).aspx

    ExportMailboxRequest and ImportMailboxRequest cmdlets do most of the heavy lifting for importing and exporting data.

    Why do you need to read messages? Powershell can also do client side scripts using Outlook library commands.

    EDIT

    Put a 'magic phrase' in your test email. "MagicRainbowUnicorn".

    1. Delete a message

      Search-Mailbox -Identity "TestMailbox" -SearchQuery 'MagicRainbowUnicorn' -DeleteContent
      
    2. Test for message

      Switch ((Search-Mailbox -Identity "TestMailbox" -SearchQuery 'MagicRainbowUnicorn').count) {
          0 { "No Results Found" }
          1 { "One Result" }
          default { "More than One, or some other strange Result" }
          }