I'm trying to write an asp.net (using c#) app that accesses my Outlook mailbox and display the messages. I searched on google but couldn't find useful info, any help is appreciated?
-
This is a strange one - perhaps you explain the reasoning behind this decision? – m.edmondson Feb 07 '11 at 14:32
-
1Outlook as in your client application? Or do you by "outlook" mean your "mail account"? Or perhaps the exchange server, that already has a web interface? – Jaroslav Jandek Feb 07 '11 at 14:35
-
I think by "Outlook", OP means "Outlook". There is only one Outlook, you know... – Gabriel Magana Feb 07 '11 at 14:38
-
2Outlook is often paired with [Exchange](http://en.wikipedia.org/wiki/Microsoft_Exchange_Server). In those cases Outlook is merely a viewing client (albeit with a local cache of the data), while Exchange holds the relevant data. Take a look at [EWS](http://blogs.msdn.com/b/exchangefaqs/archive/2008/01/23/exchange-web-service-ews.aspx) for that purpose. – Rudu Feb 07 '11 at 14:41
-
1@gmagana: There are actually multiple Outlooks (client, web, office, ...). But considering he wrote "Outlook mails" he may not mean that literally, it never hurts to ask for clarification... He may want the mails (that are on mail server), not Outlook interop... Got it? – Jaroslav Jandek Feb 07 '11 at 14:44
-
1@Jaroslav: Hmm no, there is only one Outlook. The others you mention have different names, hence are different products. – Gabriel Magana Feb 07 '11 at 15:03
-
1Which Outlook? Microsoft Office Outlook 2003/2007, Microsoft Outlook 97-2011, Outlook Express 4.0-6.0, Outlook Web Access? – Amy West Feb 08 '11 at 08:18
-
@Jaroslav you are right, I only want to access the mails nothing else. I'm using MS Outlook 2003. I want to access the mails that are in my Outlook and display the mailfrom, subject & body. – Tassisto Feb 08 '11 at 14:11
4 Answers
You must be aware of the fact that outlook is running on user local machine, and your ASP.NET application is running on some server and there is no way that your server side ASP.NET code can use Outlook local data.
AFAIK only way to do something like that would be creating outlook addin that will export all mails to ASP.NET application

- 20,445
- 6
- 75
- 102
-
I'm using MS Outlook 2003, I don't think it's possible to create an addin in MS Outlook 2003? – Tassisto Feb 08 '11 at 14:06
-
Yes, it's possible : [link](http://msdn.microsoft.com/en-us/library/aa289167%28v=vs.71%29.aspx) [link](http://blogs.msdn.com/b/dancre/archive/2004/03/21/93712.aspx?wa=wsignin1.0) – Antonio Bakula Feb 08 '11 at 14:16
-
bakula Outlook is running on Exchange Server 2007. Do you have some code to connect to ES2007? – Tassisto Feb 22 '11 at 08:06
-
no, sorry Massimo, it would be best to ask another question, and I am sure that you will get some answers – Antonio Bakula Feb 22 '11 at 09:21
If you are using Exchange then you can use Exchange Web Services to read emails.
Please see here

- 8,539
- 4
- 46
- 98

- 7,858
- 4
- 34
- 49
-
-
Also I provide a simple code sample for this here: https://stackoverflow.com/questions/652549/read-ms-exchange-email-in-c-sharp/6622250#6622250 – War Aug 28 '17 at 11:58
Be very careful that you do not attempt to access Outlook on the server side by using the Automation interfaces. All of the Microsoft Office desktop applications are written to be run by an interactive user in a process with a message pump, with all synchronization happening via the UI. When you run them in a multi-threaded environment like ASP.NET, horrible things will happen. If you're lucky, the application will simply crash.
If you're not lucky, you can suffer from data corruption, random crashes in unrelated code, and all the other things that happen when an application corrupts memory.
You may also violate your license if the people accessing the Office application through your web site are not individually licensed to use the application on their desktop.

- 160,644
- 26
- 247
- 397
-
The people that will use the application will have the rights to use it. The application needs only to access my mails and display them, that's all. I don't see what could go wrong. – Tassisto Feb 08 '11 at 14:00
-
@Massimo: didn't you get the part about it just doesn't work in a server environment? Don't waste your time. There are easier ways to torture yourself if you like that sort of thing. – John Saunders Feb 08 '11 at 14:01
-
@John: haha, I don't torture myself. But I really want to access them :p that's all. – Tassisto Feb 08 '11 at 14:15
-
@Massimo: attempting to use an Office application from a server application like ASP.NET is torturing yourself. Don't do it. Take it from someone who learned the hard way. – John Saunders Feb 08 '11 at 14:17
-
@John: Outlook is running on Exchange Server 2007. So it does work in a server environment – Tassisto Feb 22 '11 at 08:08
-
@Massimo: no, not at all. Outlook is not running in a server environment. Outlook is running on desktops, accessing server data from Exchange. This is in contrast to "running" Outlook from an ASP.NET application, which will not work. – John Saunders Feb 22 '11 at 19:09
-
It will not work if you put it on the server, you mean? Because now I can access Outlook mails directly from my asp.net – Tassisto Feb 25 '11 at 13:14
-
@Massimo: I mean Outlook, the program. Do not use Outlook, Word, Excel, or any other Office program from an ASP.NET page or web service. These are Desktop programs and assume a Desktop environment. – John Saunders Feb 25 '11 at 14:08
You can't connect to Outlook via C# (ASP.NET), but you can connect to your mailserver via POP3/IMAP to read the mail.

- 386
- 2
- 8
-
This is not correct, you can indeed connect to Outlook with C#, look at the other answers that mention Outlook addins/Interop. – Gabriel Magana Feb 07 '11 at 14:39
-
1@gmagana: Indeed, you can create an connetion to outlook from addins or via interop, but from what I know you cannot create an interop from a webpage to your local Outlook-client. I may be wrong, but I haven't found a way to do that, except if you install a client on the computer, which you call with a URL-handler – NoLifeKing Feb 07 '11 at 15:00
-
I want to create a webpage that accesses my messages of Outlook. And display them on that webpage, that I've created. – Tassisto Feb 08 '11 at 13:57
-
@Massimo, Then you'll have to access the mailserver that you use in Outlook, and fetch the mails from the server directly. You cannot access the Outlook-application directly via a webpage. If you follow the link in my answer, you will find a library that helps you do this. A good tip is to save the mails in a database of some sort, since the connection to the mailserver takes some time. – NoLifeKing Feb 08 '11 at 14:44