简体   繁体   中英

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.

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" } } 

I don't have enough reputation to comment, but could you consume Exchange Web Services with C++? I wrote a few programs in C# that use EWS for monitoring mailboxes. I had the ability to view and delete messages from Exchange.

[Edit] This is a sample of what I used in C#, if you decide to use that instead of C++. Or maybe it'll help steer you in a good direction.

using Microsoft.Exchange.WebServices.Data;

ExchangeService svc = new ExchangeService(ExchangeVersion.Exchange2010);
svc.Credentials = new WebCredentials("user@domain.com", "password");
svc.AutodiscoverUrl("user@domain.com");

// loop through messages in Inbox
foreach (EmailMessage msg in svc.FindItems(WellKnownFolderName.Inbox, new ItemView(int.MaxValue)))
{
    // do stuff with message
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM