HOWTO: Programmatically Gain Anonymous Access to Public Folders

ID: Q179332

The information in this article applies to:

SUMMARY

This article describes how to programmatically gain anonymous access to a public folder on your Microsoft Exchange Server from an Active Server Page (ASP) page.

Please note that you can gain non-programmatic anonymous access to any public folder on the Exchange Server using the built in Hypertext Transfer Protocol (HTTP) supported by Exchange Server.

MORE INFORMATION

To gain anonymous programmatic access to an Exchange Public folder from an ASP page, you need to setup several components of Windows NT, Exchange and Internet Information Server (IIS) correctly. This example creates a new user on the domain using "User Manager for Domains," the "Microsoft Exchange Administrator," and the "Internet Service Manager."

User Manager for Domains

1. Open the User Manager and from the User menu, choose New User. Set the

   following properties:

      Username:          AnonUser
      Full Name:         Anonymous User.
      Description:       For anonymous Web access to Public Folders
      Password:          Fill in an appropriate password.
      Confirm Password:  Repeat password.

      User Must Change Password at Next Logon:     OFF
      User Cannot Change Password:                 ON*
      Password Never Expires:                      ON*
      Account Disabled:                            OFF

   NOTE: You may set these values to OFF. If you set these values OFF, you
   need to change the password in the IIS Manager as well as in the
   account.

      Groups:       Member of:  Domain Users
                                Domain Guests

      Profiles:     User Profiles or Home Directory settings are not
                    required.

      Hours:        No settings are required.

      Logon to:     Set as appropriate.

      Account:      Account Expires: Never
                    Account Type:    Global Account for regular user
                                     accounts in the domain.

      Dialin:       "Grant dialin permissions to user":  OFF
                    "Call Back":  No Call Back.

2. Click Add. If you have configured your server to automatically create an
   Exchange account the Exchange User Properties dialog box appears. If
   the dialog box does not appear, you need to open the "Microsoft Exchange
   Administrator" and create a new mailbox.

3. Before or after creating the new mailbox, click User Rights from the
   Policies menu in the User Manager. Click Log on Locally from the drop-
   down menu on the right. Click Add and add the AnonUser. The user you
   created now has rights to log on locally to the IIS server.

Microsoft Exchange Administrator

1. Fill in the following properties on the General Tab:

      First Name:             Anonymous
      Last Name:              User
      Display:                Anonymous User
      Alias:                  AnonUser
      Primary NT Account:     DOMAIN\AnonUser

2. You do not need to set any other properties. Click OK.

Microsoft Internet Service Manager

1. Select the server you want anonymous users to access your Web from and

   set the following properties:

      Anonymous Logon
      ---------------

        UserName:     AnonUser
        Password:     Fill in the password you created while creating the
                      Anonymous User account. Confirm the password in the
                      appropriate dialog box.

      Password Authentication
      -----------------------

        Allow Anonymous:                   ON
        Basic (Clear Text):                As Desired
        Windows NT Challenge Response:     As Desired*
        * You may want to turn Windows NT Challenge Response ON so
        you can author to the Web from another computer.

2. Click OK and confirm the password.

Active Server Page (ASP)

Now your system is configured to allow an anonymous user to gain access to the Public Folders on your Exchange Server. Your ASP code must reflect the settings you have created. When logging into the session your code should log you onto the mailbox of "AnonUser" as demonstrated in the following code. This sample code shows how to gain access to the Internet Newsgroups folder.

Here is the sample code:

   <%@ LANGUAGE="VBSCRIPT" %>

   <HTML>
   <HEAD>
   <META NAME="GENERATOR" Content="Microsoft Visual InterDev 1.0">
   <META HTTP-EQUIV="Content-Type" content="text/html;charset=iso-8859-1">
   <TITLE>Document Title</TITLE>
   </HEAD>
   <BODY>

   <%
   CONST strServer     = "MyExchangeServer"
   CONST strMailbox    = "AnonUser"
   Dim objSession
   Dim objMessages
   Dim objOneMessage
   Dim objInfoStores
   Dim objInfoStore
   Dim objTopFolder
   Dim objFolders
   Dim objSubFolder
   Dim objTargetFolder
   Dim strProfileInfo
   Dim i
   Dim bstrPublicRootID

   strProfileInfo = strServer & vblf & strMailbox
   Set objSession = Server.CreateObject("MAPI.Session")
   objSession.Logon , , , False, , True, strProfileInfo
   Set objInfoStores = objSession.InfoStores
   For i = 1 To objInfoStores.Count
      If objInfoStores.Item(i)= "Public Folders" Then
         Set objInfoStore=objInfoStores.Item(i)
         Exit For
      End If
   Next

   bstrPublicRootID = objInfoStore.Fields.Item( &H66310102 ).Value
   Set objTopFolder = objSession.GetFolder(bstrPublicRootID, _
                      objInfoStore.ID)
   Set objFolders = objTopFolder.Folders
   Set objFolder = objFolders.GetFirst()
    Do Until objFolder.Name = "Internet Newsgroups"
      Set objFolder=objFolders.GetNext()
   Loop
   Set objMessages = objFolder.Messages
   For Each objOneMessage in objMessages
      Response.Write("objOneMessage.Subject = " & _
                     objOneMessage.Subject & "<br>")
      Response.Write("objOneMessage.Text = " & _
                     objOneMessage.Text & "<br>")
   Next
    objSession.Logoff
   Set objOneMessage = Nothing
   Set objMessages = Nothing
   Set objFolder = Nothing
   Set objTopFolder = Nothing
   Set objSession = Nothing
   %>
   </BODY>
   </HTML>

REFERENCES

For more information please see "Implementing a Secure Site with ASP," located at:

   http://www.microsoft.com/isn/techcenter/security.htm

For additional information on designating Public Folders for Web access, please see the following article in the Microsoft Knowledge Base:

   ARTICLE-ID: Q168661
   TITLE     : PRB: Accessing Public Folders Via a Web Browser Causes Error

Keywords          : kbASP kbCDO120 kbMsg kbVBScript kbGrpMsg 
Version           : WINDOWS:1.2
Platform          : WINDOWS
Issue type        : kbhowto

Last Reviewed: April 8, 1999