programming Outlook client application in .Net - CDO 1.2?

G

Guest

Hi
I need to create an outlook client application for Outlook 2000. The OS
is windows 2000 SP4. This application is supposed to log on to a Exchange
mailbox, get into a particular mail folder and save all the attachments
coming with the mails. I have an old VB program which use CDO 1.2 to do this.
Now I need to convert it to a C# program.

I have been using Outlook 9 COM to do this. It runs fine on my machine,
but once I moved the application to our application server, it does not work
anymore. The error is "Com object with CLSID xxxxxxxxx is either not
registered or not valid...". I suspect that this is due to no Office or
Outlook has been installed to the server. I don't know how to solve this
problem (we are not allowed to install MS office or outlook on the server).

So now I turn back to use CDO 1.2. I used CDO 1.2 in the same way in VB to
connect to Exchange server. So far I have no problem connecting to the
server and log on the mailbox. The big problem is that I have difficulty
getting the emails from any of the folders. It couldn't get anything from
the mailbox except the root folders. Below is my code:

mSession.Logon(null, passwd, false, true,null,null,mailServer+"\n"+mailID);
MAPI.InfoStores mInfoStores = (MAPI.InfoStores) mSession.InfoStores;
for (int i=1; i<=(int)mInfoStores.Count; i++)
{
MAPI.InfoStore mInfoS = (MAPI.InfoStore) mInfoStores.get_Item(i);
Console.WriteLine(mInfoS.Name);
}

/********
This outputs:
" Public Folders
Mailbox - c2chuc
"
as expected
****/
MAPI.InfoStore inStore = (MAPI.InfoStore) mInfoStores.get_Item("Mailbox -
c2chuc");
MAPI.Folder rootFld = (MAPI.Folder) inStore.RootFolder;
MAPI.Folders objFolders = (MAPI.Folders ) rootFld.Folders;
for (int i=1; i<=(int) objFolders.Count; i++)
{
MAPI.Folder objF = (MAPI.Folder) objFolders.get_Item(i);
Console.WriteLine(objF.Name);
if (objF.Name.Equals("Inbox"))
{
Console.WriteLine("*********Got inbox*********");
MAPI.Folders tmpFlds =(MAPI.Folders) objF.Folders;
for (int j=1; j<=(int) tmpFlds.Count; j++)
{
MAPI.Folder tmpFld = (MAPI.Folder)tmpFlds.get_Item(j);
Console.WriteLine(tmpFld.Name);
}
MAPI.Messages objML = (MAPI.Messages) objF.Messages;
Console.WriteLine( "Mail count ="+ objML.Count);
for (int k=1; k<=(int)objML.Count; k++)
{
MAPI.Message objMessage = (MAPI.Message) objML.get_Item(k);
Console.WriteLine(k+" Sender = " + objMessage.Sender );
Console.WriteLine("Subject = " + objMessage.Subject);
Console.WriteLine("TimeReceived = " + objMessage.TimeReceived);
Console.WriteLine("Recipients = " + objMessage.Recipients);
Console.WriteLine("Text = " + objMessage.Text);
MAPI.Attachments objAttachmentList = (MAPI.Attachments)
objMessage.Attachments;
for (int l=1; l<=(int)objAttachmentList.Count; l++)
{
MAPI.Attachment objAttachment = (MAPI.Attachment)
objAttachmentList.get_Item(l);
Console.WriteLine( "Attachment = " + objAttachment.Name );
}
}
Console.WriteLine("*********end inbox*********");
}
}

This outputs :
"Calendar
Contacts
Deleted Items
Drafts
Inbox
*********Got inbox*********
Mail count =2
1 Sender = System.__ComObject
Subject = link to your folder
TimeReceived = 10/15/2003 3:42:42 PM
Recipients = System.__ComObject
Text =

Attachment = Chu, Kate.xnk
2 Sender = System.__ComObject
Subject = test
TimeReceived = 10/21/2003 3:59:58 PM
Recipients = System.__ComObject
Text = test

*********end inbox*********
Journal
Notes
Outbox
Sent Items
Tasks"

This is not right, because I do have 2 subfolders under "Inbox", but it does
not find it. And the 2 emails it found "link to your folder" and "test", are
not the mails in my "inbox". I have no idea what those are.

I also tried to modify my code using a different way to get the mails from
inbox:
............ (after log on and get the inStores) .......
MAPI.InfoStore inStore = (MAPI.InfoStore) mInfoStores.get_Item("Mailbox -
c2chuc");
MAPI.Folder rootFld = (MAPI.Folder) inStore.RootFolder;
MAPI.Folder fldRoot = (MAPI.Folder) mSession.GetFolder(rootFld.FolderID,
rootFld.StoreID);
MAPI.Folders objFolders = (MAPI.Folders ) fldRoot.Folders;
MAPI.Folder objFolder = (MAPI.Folder) objFolders.get_Item("Inbox");
MAPI.Messages objMessageList = (MAPI.Messages) objFolder.Messages;
if((int) objMessageList.Count == 0)//objMessage Is Nothing
{
Console.WriteLine( "No Mail");
}
.....

And I got :"
No Mail
"

Now I am stuck. Can someone help me on this issue?

Thanks a lot.
 
T

Tom Rizzo [MSFT]

How'd you get CDO 1.21 on the app server? Outlook and Exchange (or the
Exchange 2003 administrative tools) are the only ways to get it on a box.

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top