Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ADO.NET and MS Outlook/Exchange

2 views
Skip to first unread message

Rob Thomas

unread,
Mar 25, 2002, 12:59:13 PM3/25/02
to
Hello,

Can somebody please give me an example of how to use ADO.NET with Microsoft
Outlook ?
I need to be able to look at the message subject and body of all messages
sent to a pre-defined recipient.
The most important thing that I need is an example of how to open the
connection to the mail server.

Thanks
Rob


Keith Fink (MS)

unread,
Mar 25, 2002, 7:16:42 PM3/25/02
to


Hi Rob,

Unfortunately there's not a managed provider I know of that exposes this functionality. You can go through the Jet OLEDB provider and use
its Outlook/Exchange ISAM to get to Exchange data. Here is a sample of how to do that.

In order for this to work, you need to know the name of the mailbox, the local Exchange/Outlook profile and the path to the Temp folder on
the machine. This example opens a dataset and retrieves the subject and body of all messages in the Inbox and then displays it in a
datagrid.

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New DataSet()
Dim dt As DataTable

Try
Dim da As New OleDbDataAdapter("SELECT Subject, Contents FROM Inbox", _
"Provider=Microsoft.Jet.OLEDB.4.0;Outlook 9.0;" & _
"MAPILEVEL=Mailbox - James Smith|;PROFILE=Outlook;" & _
"TABLETYPE=0;DATABASE=C:\Windows\Temp")

da.Fill(ds, "Outlook")
dt = ds.Tables("Outlook")
DataGrid1.DataSource = dt
Catch exc As OleDbException
Dim OleDBError1 As OleDbError
For Each OleDBError1 In exc.Errors
Console.WriteLine(OleDBError1.Message)
Next
End Try
End Sub

For more information, see this article on how to do it with classic ADO. It should help out with doing it in ADO.NET.

ID: Q275262
ACC2000: How to Retrieve Exchange and Outlook Data with OLEDB
http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q275262


Sincerely,

Keith Fink
Microsoft Developer Support

This posting is provided “AS IS” with no warranties, and confers no rights.

Rob Thomas

unread,
Mar 26, 2002, 3:43:23 AM3/26/02
to

Thanks Keith.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Rob Thomas

unread,
Mar 26, 2002, 5:07:00 AM3/26/02
to
Keith,

Thanks for the info. I have been trying to get this to work but I keep
on getting the following error message when I try to populate the
dataset:

"Cannot find instalable ISAM".

I can use the "Microsoft.JET.OLEDB.4.0" provider to connect to an Access
database so I can't see why I should get this message.

I have replaced the mailbox name of "James Smith" in your example with
the relevant mailbox name but I am still unsure about a few things. The
first is when you said that I need to know the name of "the local
Exchange/Outlook profile", is this the name of the mail server ?

Also, how will this code connect to the mail server if I am not
supplying any passwords etc ?

Thanks again for your help,
Rob

_alt.0

Keith Fink (MS)

unread,
Mar 26, 2002, 11:09:04 AM3/26/02
to
Hi Rob,

<<<I have replaced the mailbox name of "James Smith" in your example with
the relevant mailbox name but I am still unsure about a few things. The
first is when you said that I need to know the name of "the local
Exchange/Outlook profile", is this the name of the mail server ?>>>

No, its not the name of the mail server. You actually need to use the name of the profile that Outlook will be using. You can get the name of
the profile by opening the Control Panel and double clicking the Mail icon. You should see the profiles (by default there is just one, but
you can create more) that are defined on the machine. It will probably be named something like "MS Exchange Settings" or "Outlook". Click the
Delivery tab to see the list of available mailboxes. Your mailbox name is in the "Deliver new mail to the following location" box. For
Exchange servers, the mailbox name typically looks like "Mailbox - James Smith" or "Personal Folders", depending on if the mail is being
delivered to a server or a local store.

<<<Also, how will this code connect to the mail server if I am not
supplying any passwords etc ?>>>

For Exchange servers, I believe that it will be using NT authentication and you shouldn't have to supply a password. If you're not using
Exchange (i.e. using Outlook for Internet mail), I'm not sure the ISAM will work. But with Internet email, the profile allows you to store
the servername/password within it so that the profile will authenticate you.

Hope this helps!

Rob Thomas

unread,
Mar 26, 2002, 11:43:54 AM3/26/02
to
Keith,

Thanks for that, it all appears to be working now.

Thanks again,

Rob Thomas

unread,
Mar 27, 2002, 5:00:48 AM3/27/02
to
Keith,

Sorry to be a pain but the code that you sent me above now works fine in
my sample windows app, but when I then copy and paste the code into my
intended ASP.NET app, I get the following error message when it gets to
the point of populating the dataset:

There are no MAPI clients installed on this machine. Install a MAPI
client (like Outlook) on this machine.

I am using the same machine to develop the ASP.NET page that I used to
develop the sample windows app. The ASP.NET page is also running on the
local web server so everything should match up.

Any additional advice that you can give me would be appreciated - again
!

Thanks

0 new messages