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
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