Getting Well-Known Mailbox Folder URLs

Getting Well-Known Mailbox Folder URLs

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

Each user's mailbox folder has a set of properties that you can use to retrieve URLs for well-known subfolders such as Inbox, Calendar, Drafts, and Tasks. Additionally, you can retrieve the Microsoft® Exchange mail submission Uniform Resource Identifier (URI) that is used to send messages through WebDAV or the Exchange OLE DB (ExOLEDB) provider. The returned URLs are localized into the language that is used by the client.

The following table lists the properties that return these URLs and that are retrieved from a user's root mailbox folder.

Property Well-known folder (English)
urn:schemas:httpmail:calendar Calendar
urn:schemas:httpmail:contacts Contacts
urn:schemas:httpmail:deleteditems Deleted Items
urn:schemas:httpmail:drafts Drafts
urn:schemas:httpmail:inbox Inbox
urn:schemas:httpmail:journal Journal
urn:schemas:httpmail:notes Notes
urn:schemas:httpmail:outbox Outbox
urn:schemas:httpmail:sentitems Sent Items
urn:schemas:httpmail:tasks Tasks
urn:schemas:httpmail:sendmsg Exchange Mail Submission URI
urn:schemas:httpmail:msgfolderroot Mailbox folder (root)

To access these properties:

  1. Bind to the user's root mailbox folder. You can either request the server and username from the client to construct this initial URL or search Microsoft Active Directory® for the user's homeMDB attribute. From the value of this attribute, you can get the server on which the user's private mailbox is stored.
  2. Use the values of these properties to bind to these folders in a mailbox folder.

VBScript

<Job id="printMailboxURLs">

<reference object="ADODB.Record"/>
<reference object="CDO.Message"/>

<script language="VBScript">

userName   = WScript.Arguments.Item(0)

set info   = createobject("adsysteminfo")
set infoNT = CreateObject("WinNTSystemInfo")

urls = getStdWellKnownMailboxURLs("http://" & lcase(infoNT.ComputerName) & "." & _
                                 Info.domaindnsname & "/exchange/" & userName, _
                                 "ExOLEDB.DataSource")

wscript.echo "Well-known mailbox file: URLs for local mailbox: " & userName
wscript.echo "========================================"

For i = LBound(urls) to UBound(urls) step 2
 wscript.stdout.write urls(i)
 if Len(urls(i)) > 7 then
  wscript.stdout.write vbTab
 else
  wscript.stdout.write vbTab & vbTab
 end if
 wscript.stdout.write urls(i+1) & vbCrLf
next


Function getStdWellKnownMailboxURLs( mailboxFolderURL, provider )

 If Not TypeName(mailboxFolderURL) = "String" Then
  Err.Raise  &H80070057 ' E_INVALIDARG
 End If


 Dim Rec
 Set Rec = CreateObject("ADODB.Record")
 Dim Conn
 Set Conn = CreateObject("ADODB.Connection")
 Conn.Provider =  provider
 Conn.Open mailboxFolderURL

 Rec.Open mailboxFolderURL, Conn
 Set Flds = Rec.Fields

 ' The constants used here are defined in the CDOEx.dll type library.
 ' They are imported using the <reference> element above.

 getStdWellKnownMailboxURLs = Array( _
              "Calendar" , Flds(cdoCalendarFolderURL), _
              "Contacts" , Flds(cdoContactFolderURL), _
              "DeletedIt", Flds(cdoDeletedItems), _
              "Inbox"    , Flds(cdoInbox), _
              "Journal"  , Flds(cdoJournal), _
              "MsgRoot"  , Flds(cdoMsgFolderRoot), _
              "Notes"    , Flds(cdoNotes), _
              "Outbox"   , Flds(cdoOutbox), _
              "SendMsg"  , Flds(cdoSendMsg), _
              "SendItems", Flds(cdoSentItems), _
              "Tasks"    , Flds(cdoTasks) )

' Clean up.
Conn.Close
Rec.Close

Set Conn = Nothing
Set Rec = Nothing


End Function

</script>

</Job>

C++

#import <msado15.dll> no_namespace
#import <c:\program files\common files\microsoft shared\cdo\cdoex.dll> no_namespace
#include <iostream.h>

// Note: It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
void printMailboxFolders(bstr_t mailtoUrl) {

   IMailboxPtr iMbx;
   try {
      iMbx = getIMailbox(mailtoUrl);
   }
   catch(_com_error e) {
      throw e;
   }

   cout << "BaseFolder: " << iMbx->BaseFolder << endl;
   cout << "Inbox: "      << iMbx->Inbox << endl;
   cout << "Calendar: "   << iMbx->Calendar << endl;
   cout << "Drafts: "     << iMbx->Drafts << endl;

   //...

   IDataSourcePtr iDsrc;
   iDsrc = iMbx;
   cout << iDsrc->SourceURL << endl;
   _RecordPtr Rec(__uuidof(Record));
   _ConnectionPtr Conn(__uuidof(Connection));
   Conn->Provider = "ExOLEDB.DataSource";
   bstr_t sSendMsgUrl;
   try {
      Conn->Open(iMbx->BaseFolder, bstr_t(),bstr_t(), -1);
      Rec->Open(iMbx->BaseFolder, variant_t((IDispatch*)Conn, true), adModeRead, adFailIfNotExists, adOpenRecordUnspecified, bstr_t(), bstr_t());
      sSendMsgUrl = bstr_t(Rec->Fields->Item["urn:schemas:httpmail:sendmsg"]->Value);
   }
   catch(_com_error e) {
      cout << "Error binding to user's base mailbox folder. " << endl;
      throw e;
   }
   cout << "Mail Submission URI: " << sSendMsgUrl << endl;

   // Close the connection and record.
   Conn->Close();
   Rec->Close();
   Rec = NULL;
   Conn = NULL;

}

// Note: It is recommended that all input parameters be validated when they are
// first obtained from the user or user interface.
IMailboxPtr getIMailbox( bstr_t mailtoUrl) {

   IPersonPtr Per(__uuidof(Person));
   IDataSourcePtr Dsrc;
   Dsrc = Per;
   try {
      Dsrc->Open(mailtoUrl, NULL, adModeRead, adFailIfNotExists, adOpenRecordUnspecified, bstr_t(),bstr_t());
   }
   catch(_com_error e) {
      throw e;
   }

   return Per;
}

Send us your feedback about the Microsoft Exchange Server 2003 SDK.

Build: June 2007 (2007.618.1)

© 2003-2006 Microsoft Corporation. All rights reserved. Terms of use.