Click here to Skip to main content
15,868,164 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I wish to read an outlook message.

With mapi I am able to read a part of data.

For example I am able to read serer mail, subject mail, body text but I am not able to read datetime of mail and Cc of mail. I have downloaded this source project Reading an Outlook MSG File in C#[^]

But here doesn't use mail date time sender and CC.

In which way can i obtain this data??

I use OutlookStorage.Message message but I have not found my information in message.

In this variable I have found only body text, subject, displayname, recipients etc.

Thanks a lot
Posted
Updated 20-Dec-11 3:40am
v2
Comments
Pete O'Hanlon 20-Dec-11 9:41am    
You really should ask your question on the forum of that article. The author is the best placed person to answer you, and it's extremely unlikely that he's just going to happen by and solve an issue like that.

1 solution

C#
using Office = Microsoft.Office.Core;
using Outlook = Microsoft.Office.Interop.Outlook;


Outlook.Application outlook = new Outlook.ApplicationClass();
                Outlook.NameSpace ns = outlook.GetNamespace("Mapi");
                Outlook.Recipient oRecip = ns.CreateRecipient("INBOX");
                oRecip.Resolve();
                if (oRecip.Resolved)
                {
                    Outlook.MAPIFolder oInbox = ns.GetSharedDefaultFolder(oRecip, Outlook.OlDefaultFolders.olFolderInbox);
                    //Outlook.Items oInboxMsgs = oInbox.Items;
                    //MessageBox.Show(oInboxMsgs.Count.ToString());
                    if (oInbox.Items.Count > 0 && oInbox.Items.Count != null)
                    {
                        for (int i = 1; i <= oInbox.Items.Count; i++)
                        {
                            //item = (Microsoft.Office.Interop.Outlook.PostItem)oInbox.Items[i];
                            if (oInbox.Items[i] is Outlook.MailItem)
                            {
                                Outlook.MailItem mailItem = oInbox.Items[i] as Outlook.MailItem;
                                ProcessMailItem(mailItem);
                                mailItem.UnRead = false;
                            }
}
}
}


This way you can use the Mailitem object in the Office interop which has all the info you need/want
 
Share this answer
 
Comments
chira8 22-Dec-11 4:46am    
i have have tried to use your code but doesn't work.
ns.CreateRecipient("INBOX") gives me this error:
Chiamata di sistema non riuscita. (Eccezione da HRESULT: 0x80010100 (RPC_E_SYS_CALL_FAILED))
i have tried also in this way:

inboxFolder = ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
subFolder = inboxFolder.Folders[1];
but inboxFolder hasn't folders
why??
what can i do??

thanks a lot
Mendor81 22-Dec-11 6:33am    
First question, Do you have outlook installed?
Second, i think that depending the Outlook version you might need to authorise access from external programms to the inbox.
Try using the programm with outlook running
chira8 23-Dec-11 2:22am    
yes a have. outlook 2007 (italian language).
in which way i can authorize my inbox folder?
when i have done my test, outlook was running, infact i have done drag and drop with a message outlook
Mendor81 23-Dec-11 2:46am    
Hmm i use that code at daily bases with Outlook 2003
Normaly when you execute the code outlook by itsself pops up a windows asking to authorize a programm to access the inbox.

The only thing that changes is the name of my Inbox which is the actual name of the exchange login/account.

Outlook.Recipient oRecip = ns.CreateRecipient("Your Exchange account");


if that doesn't work im out of ideas.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900