I need the ability to monitor for and read email from a particular mailbox on a MS Exchange Server (internal to my company). I also need to be able to read the sender's email address, subject, message body and download an attachment if any.
What is the best way to do this using C# (or Vb.net)?
You should be able to use MAPI to access the mailbox and get the information you need. Unfortunately the only .NET MAPI library (MAPI33) I know of seems to be unmaintained. This used to be a great way to access MAPI through .NET, but I can't speak to its effectiveness now. There's more information about where you can get it here: Download location for MAPI33.dll?
If your Exchange server is configured to support POP or IMAP, that's an easy way out.
Another option is WebDAV access. there is a library available for that. This might be your best option.
I think there are options using COM objects to access Exchange, but I'm not sure how easy it is.
It all depends on what exactly your administrator is willing to give you access to I guess.
I got a solution working in the end using Redemption, have a look at these questions...
Using Redemption...
Using Redemption on a 64 bit machine
One option is to use Outlook. We have a mail manager application that access an exchange server and uses outlook as the interface. Its dirty but it works.
Example code:
It's a mess. MAPI or CDO via a .NET interop DLL is officially unsupported by Microsoft--it will appear to work fine, but there are problems with memory leaks due to their differing memory models. You could use CDOEX, but that only works on the Exchange server itself, not remotely; useless. You could interop with Outlook, but now you've just made a dependency on Outlook; overkill. Finally, you could use Exchange 2003's WebDAV support, but WebDAV is complicated, .NET has poor built-in support for it, and (to add insult to injury) Exchange 2007 nearly completely drops WebDAV support.
What's a guy to do? I ended up using AfterLogic's IMAP component to communicate with my Exchange 2003 server via IMAP, and this ended up working very well. (I normally seek out free or open-source libraries, but I found all of the .NET ones wanting--especially when it comes to some of the quirks of 2003's IMAP implementation--and this one was cheap enough and worked on the first try. I know there are others out there.)
If your organization is on Exchange 2007, however, you're in luck. Exchange 2007 comes with a SOAP-based Web service interface that finally provides a unified, language-independent way of interacting with the Exchange server. If you can make 2007+ a requirement, this is definitely the way to go. (Sadly for me, my company has a "but 2003 isn't broken" policy.)
If you need to bridge both Exchange 2003 and 2007, IMAP or POP3 is definitely the way to go.
Um,
I might be a bit too late here but isn't this kinda the point to EWS ?
https://msdn.microsoft.com/en-us/library/dd633710(EXCHG.80).aspx
Takes about 6 lines of code to get the mail from a mailbox: