Thomas Grossen
Guest
|
Hi Guys,
I need to scan all inbox in Outlook 2003. I have no problem if there is only one e-mail account, using GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox). But how can I get the default inbox of each accounts?
If have tried to scan all folders in NameSpace.Session.Folders, but it does not work because email get into a subfolder "Inbox".
Any idea?
Thank you,
Thomas. |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
Hi Thomas.
Sorry for delay. For some reason I didn't find your message in my Inbox.
If have tried to scan all folders in NameSpace.Session.Folders, but it does not work because email get into a subfolder "Inbox".
Please use the code below to get the full folder name.
internal string GetFullFolderName(object folder, bool clearFolderInterface)
{
object _folder = null;
object folderObj = null;
IntPtr ifolder = new IntPtr();
string fullName = String.Empty, tmp;
Guid folderGuid = new Guid("00063006-0000-0000-C000-000000000046");
IntPtr unk = Marshal.GetIUnknownForObject(folder);
if (unk == IntPtr.Zero) return String.Empty;
try
{
if (clearFolderInterface)
folderObj = folder;
else
folderObj = Marshal.GetObjectForIUnknown(unk);
_folder = folderObj;
Marshal.QueryInterface(unk, ref folderGuid, out ifolder);
Marshal.Release(unk);
while(ifolder != IntPtr.Zero)
{
Marshal.Release(ifolder); ifolder = IntPtr.Zero;
tmp = Convert.ToString(folderObj.GetType().InvokeMember("Name", BindingFlags.GetProperty, null, folderObj, null));
fullName = "\\"+tmp+fullName;
try
{
_folder = folderObj.GetType().InvokeMember("Parent", BindingFlags.GetProperty, null, folderObj, null);
}
catch
{
_folder = null;
}
finally
{
Marshal.ReleaseComObject(folderObj);
folderObj = null;
}
if (_folder != null)
{
unk = Marshal.GetIUnknownForObject(_folder);
Marshal.QueryInterface(unk, ref folderGuid, out ifolder);
Marshal.Release(unk);
folderObj = _folder;
}
}
if (fullName != String.Empty && fullName[0] == '\\') fullName = fullName.Remove(0, 1);
}
finally
{
if (folderObj != null)
Marshal.ReleaseComObject(folderObj);
}
return fullName;
}
|
|
Thomas Grossen
Guest
|
Hi Sergey,
Thank you for the sample, but this is not what I am looking for. Let me explain better:
In my case I have 3 different email account, one on Exchange Server, one that is an IMAP and another an POP3. Each one goes to a different pst file.
I want to handle email when they arrive. For this, there is no problem in the Default inbox, I use
GetDefaultFolder(Outlook.OlDefaultFolders.olFolderInbox).
My problem is to get the Inbox folders for the 2 other accounts.
I don't know if this is clear... :)
Thank you,
Thomas |
|
Sergey Grischenko
Add-in Express team
Posts: 7233
Joined: 2004-07-05
|
I know that it can be done via Extended MAPI.
You can use the IMAPISession and IMsgStore interfaces to access all message stores. To acceess the Inbox within the message store you can use the GetReceiveFolder method of the IMsgStore interface.
Another solution is to find all inboxes in a loop over all folders while the add-in starts. |
|
Thomas Grossen
Guest
|
I Sergey,
Thank you for your help. After sending some time with Extended MAPI, I used the solution to find all inboxes in all folders :).
Thank you,
Thomas. |
|