tags:

views:

2924

answers:

5

Hi,

Thats what I am using to read email using C#:

outLookApp.NewMailEx += new ApplicationEvents_11_NewMailExEventHandler(outLookApp_NewMailEx);
            Outlook.NameSpace olNameSpace = outLookApp.GetNamespace("mapi");

        olNameSpace.Logon("xxxx", "xxxxx", false, true);
        Outlook.MAPIFolder oInbox  = olNameSpace.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox);
        Outlook.Items oItems  = oInbox.Items;
        MessageBox.Show("Total : " + oItems.Count); //Total Itemin inbox
         oItems = oItems.Restrict("[Unread] = true");
         MessageBox.Show("Total Unread : " + oItems.Count); //Unread Items
         Outlook.MailItem oMsg;


         Outlook.Attachment mailAttachement;
         for (int i = 0; i < oItems.Count; i++)
         {
             oMsg = (Outlook.MailItem)oItems.GetFirst();

             MessageBox.Show(i.ToString());
        MessageBox.Show(oMsg.SenderName);
        MessageBox.Show(oMsg.Subject);
        MessageBox.Show(oMsg.ReceivedTime.ToString());
        MessageBox.Show(oMsg.Body);

The problem that I am facing is this application only works if the outlook is open on the machine. If outlook is closed it throws an exception: The server is not available. Contact your administrator if this condition persists. Is there anyway I can read email with outlook open. Thanks

A: 

You'll likely run into this when Outlook is closed.

Also following this tutorial will ensure you're doing all the right steps part and parcel.

Best of luck!

Mat Nadrofsky
A: 

Are you sure you want to use Outlook as a proxy?

people seems to deal low level with such a task in C# (surprising there isn't any built-in component in the framework...)

Concerning Mat's response, Redemption is indeed a fine product (used it to parse mails upon arrival in outlook), but I doubt it can work without outlook running.

Vinzz
+1  A: 

I would personally not use Outlook as proxy. If you're trying to ultimately montiro an Exchange store, then I'd use WebDav. Your Exchange server must support it - but if it does, it's a simple XML API. Well, the API bit is simple, but the XML is quite convoluted. But once you've encapsulated this in a bit of code, it's a doddle to use.

Steve Dunn
A: 

is it possible to read the content of an email

A: 

Use the Redemption COM module for your code.

http://www.dimastr.com/redemption/