How to connect exchange server using .Net

G

Guest

Hi,

I try to connect to Exchange server using MAPI. I need to access a special
user inbox and read all his new mails.
The code I wrote work good, but I get my inbox instead of the user I need.
Here the code :

MAPI.Session objSession;

MAPI.Folder objFolder ;

MAPI.Messages objMessageList;

MAPI.Attachments objAttachmentList;

MAPI.Attachment objAttachment;

MAPI.MessageFilter objFilter;



string strUser = "Scott";

string strPass = "123456";

string strServer = "MAILIT";

try

{

objSession = new MAPI.SessionClass();

objSession.Logon(strUser, strPass, true, false, 0, true, strServer + "\n" +
strUser);

//For Inbox

objFolder =
(MAPI.Folder)objSession.GetDefaultFolder(MAPI.CdoDefaultFolderTypes.CdoDefaultFolderInbox);

objMessageList = (MAPI.Messages)objFolder.Messages;

objFilter = (MAPI.MessageFilter)objMessageList.Filter;

objFilter.Unread = true;

objFilter.Type = "IPM.Note";

if ((int)objMessageList.Count > 0)

{

MAPI.Message objMessage;

for(int i=0;i<(int)objMessageList.Count;i++)

{

objMessage = (MAPI.Message)objMessageList.GetNext();

MessageBox.Show(objMessage.Subject.ToString() + "\n" +

objMessage.Sender.ToString() + "\n" +

objMessage.TimeSent.ToString());

}

}

if (objSession != null)

objSession.Logoff();

}

catch (Exception ex)

{

MessageBox.Show(ex.Message);

}


Why I get my inbox instead of Scotts inbox ?

Thanks,

David
 
H

Henning Krause [MVP - Exchange]

Hello David,

MAPI is not supported from a managed process (it's memory management
collides with the .NET garbage collector).

Your are better of using WebDAV (in case of Exchange 2003) or WebServices
(in case of Exchange 2007) to access the folder.

I have plenty of information on my website (www.infinitec.de).

And here is the WebDAV reference on MSDN:
http://msdn2.microsoft.com/en-us/library/aa486282.aspx

Kind regards,
Henning
 
G

Guest

Hi Henning,

It's the first time I hear about webdav. I have to learn it first.
Thanks a lot for your help .

David
 

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