M
mariaip
Please help,
I am using C# for reading through the subject of the mail. M
code is as follows:
static void Main(string[] args)
{
ApplicationClass appoutlook = new ApplicationClass();
Class1.DisplayInbox(appoutlook);
}
//DisplayInbox() obtains the current MAPI namespace in order t
retrieve each MailItem in the Inbox folder.
public static void DisplayInbox(ApplicationClass o)
{
// Get items in my inbox.
NameSpace outlookNS = o.GetNamespace("MAPI");
MAPIFolder inboxFolder
outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Console.WriteLine("You have {0} e-mails.", inboxFolder.Items.Count);
Console.WriteLine();
foreach(object obj in inboxFolder.Items)
{
MailItem item = obj as MailItem;
if (item != null)
{
Console.WriteLine("Sender: {0}", item.SenderName);
Console.WriteLine("Subject: {0}", item.Subject);
}
}
}
However it is giving me the following error on foreach:
foreach statement cannot operate on variables of type
'Outlook.Items' because 'Outlook.Items' does not contain a definition
for 'GetEnumerator', or it is inaccessible
I am using C# for reading through the subject of the mail. M
code is as follows:
static void Main(string[] args)
{
ApplicationClass appoutlook = new ApplicationClass();
Class1.DisplayInbox(appoutlook);
}
//DisplayInbox() obtains the current MAPI namespace in order t
retrieve each MailItem in the Inbox folder.
public static void DisplayInbox(ApplicationClass o)
{
// Get items in my inbox.
NameSpace outlookNS = o.GetNamespace("MAPI");
MAPIFolder inboxFolder
outlookNS.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
Console.WriteLine("You have {0} e-mails.", inboxFolder.Items.Count);
Console.WriteLine();
foreach(object obj in inboxFolder.Items)
{
MailItem item = obj as MailItem;
if (item != null)
{
Console.WriteLine("Sender: {0}", item.SenderName);
Console.WriteLine("Subject: {0}", item.Subject);
}
}
}
However it is giving me the following error on foreach:
foreach statement cannot operate on variables of type
'Outlook.Items' because 'Outlook.Items' does not contain a definition
for 'GetEnumerator', or it is inaccessible