How to connect exchange server using .Net
How to connect exchange server using .Net
am 13.11.2007 14:48:00 von davide
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.CdoDefaultFold erTypes.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
Re: How to connect exchange server using .Net
am 13.11.2007 17:59:04 von newsgroups_remove
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
"DavidE" wrote in message
news:E3D71B22-E6DC-4E7F-8EB0-4AD8A07422C0@microsoft.com...
> 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.CdoDefaultFold erTypes.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
>
>
>
>
Re: How to connect exchange server using .Net
am 13.11.2007 22:26:00 von davide
Hi Henning,
It's the first time I hear about webdav. I have to learn it first.
Thanks a lot for your help .
David
"Henning Krause [MVP - Exchange]" wrote:
> 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
>
>
> "DavidE" wrote in message
> news:E3D71B22-E6DC-4E7F-8EB0-4AD8A07422C0@microsoft.com...
> > 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.CdoDefaultFold erTypes.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
> >
> >
> >
> >
>
>