access mail from public folder

  • Thread starter Thread starter mithilesh
  • Start date Start date
M

mithilesh

Hi,

I'm trying to use outlook 2003 and access mail from public folder.

storeId and mail Count is giving result but access mail mi.Subject have no
any output. I am losing any scop for public folder.

Outlook.NameSpace mapiNamespace = applicationObject.GetNamespace("MAPI");

Outlook.MAPIFolder inboxFolder =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);
Outlook.MAPIFolder addinboxFolder =
inboxFolder.Folders["Public_folder"];

string storeId = addinboxFolder.StoreID;
MessageBox.Show(addinboxFolder.Items.Count.ToString(), "Count");
MessageBox.Show(storeId, "storeId ");

foreach (object oitems in addinboxFolder.Items)
{
MailItem mi = oitems as MailItem;
MessageBox.Show(mi.Subject);
}
 
From that snippet it doesn't look like a scoping problem.

Are you positive the items are Class == olMail?

Have you checked in the loop that addinboxFolder retains its scope?

Are you getting any exceptions?

See if instantiating an Items collection object variable helps.
 
In the loop addinboxFolder retains its scope. Coz, In the loop
addinboxFolder.Display() is open Public Folder.

NO, I am not getting any exception. While declared mi.Subject, execute the
statement before mi.subject but after mi.subject statement is not executing.
If mi.subject is comment then execute all statement.

While selecting folder Inbox inside of Public then same code execute proper
without any trouble.

Can I access Public folder mail by this way?




Ken Slovak - said:
From that snippet it doesn't look like a scoping problem.

Are you positive the items are Class == olMail?

Have you checked in the loop that addinboxFolder retains its scope?

Are you getting any exceptions?

See if instantiating an Items collection object variable helps.




mithilesh said:
Hi,

I'm trying to use outlook 2003 and access mail from public folder.

storeId and mail Count is giving result but access mail mi.Subject have no
any output. I am losing any scop for public folder.

Outlook.NameSpace mapiNamespace = applicationObject.GetNamespace("MAPI");

Outlook.MAPIFolder inboxFolder =
mapiNamespace.GetDefaultFolder(Outlook.OlDefaultFolders.olPublicFoldersAllPublicFolders);
Outlook.MAPIFolder addinboxFolder =
inboxFolder.Folders["Public_folder"];

string storeId = addinboxFolder.StoreID;
MessageBox.Show(addinboxFolder.Items.Count.ToString(), "Count");
MessageBox.Show(storeId, "storeId ");

foreach (object oitems in addinboxFolder.Items)
{
MailItem mi = oitems as MailItem;
MessageBox.Show(mi.Subject);
}
 
You certainly should be able to access items that way, assuming you have
sufficient permissions on that folder.

About the only thing I can think of would be to simplify the loop and step
it to see what's going on:

Outlook.Items items = addinboxFolder.Items;
int count = items.Count;
for (int i = 1; i <= count; i++)
{
object item = items;
if (item.Class == Outlook.OlObjectClass.olMail)
{
Outlook.MailItem mail = (Outlook.MailItem)item;
MessageBox.Show(mail.Subject);
}
}

See what you come up with.
 
Back
Top