473,325 Members | 2,774 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

How to connect exchange server using .Net

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.CdoD efaultFolderTypes.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


Nov 13 '07 #1
2 4239
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" <Da****@discussions.microsoft.comwrote in message
news:E3**********************************@microsof t.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.CdoD efaultFolderTypes.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

Nov 13 '07 #2
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" <Da****@discussions.microsoft.comwrote in message
news:E3**********************************@microsof t.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.CdoD efaultFolderTypes.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



Nov 13 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: aka | last post by:
Hi I have a DB2 v8.1 on AIX and DB2 Connect EE on Solaris wich is connected to OS/390 DB2 subsystems via APPC / SNA. I have cataloged the DB2 Connect instance as tcpip node and then the Host DB...
3
by: hkappleorange | last post by:
I connect to mdb file using the following codes. How should I modify it if I want to connect to Excel instead ? <%@ Import Namespace="System.Data.OleDb" %> <% Dim conAuthors As...
3
by: Christoph M?der | last post by:
Hello, i am writting an programm which should connect to an exchange server and get calendar entries. i have tried it with ADODB, but there was a problem: sometimes it works, sometimes not. ...
2
by: Mike | last post by:
I need to create a front end for the users to enter in some data, but the data needs to go to a folder on the exchange server. How can I add, view, and modify items in outlook (exchange) folders. I...
4
by: dezso.bolyan | last post by:
Hallo! I need to connect to MS Exchange Server and get any email with attechments. Use of IMAP and POP3 are not allowed on this Exchange Server. Have anybody any idea, how can I resolve this...
1
by: Jim H | last post by:
I want to write an outlook plug-in or even a separate app if necessary to connect to an exchange server to get mail off of it. My outlook is currently connected to Exchange server A, I need to get...
1
by: vibhavleo | last post by:
I am using the Microsoft Office 11.0 Object library to connect to outlook. My code is as follows: _ApplicationPtr application("Outlook.Application"); CComPtr<_NameSpace> ns;...
1
by: edcba | last post by:
Hello, I am required to write a C# app to connect to an exchange server using .Net 3.5. The aim will be then to receive emails and insert the email text into a database table. My first question...
1
by: chelluchittibabu | last post by:
hi, pls tell me if you know regarding ms exchange server 2007. In my system i am using windows 2003. what i want is 1. how to connect ms exchange server 2007 from .net 2. how to get data...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.