401 errors using WebDAV to access a newly created mailbox

I recently worked on a issue where the customer was programmatically creating mailboxes on an Exchange server with CDOEM and ADSI, and were having some issues trying to access these newly created mailboxes with their WebDAV code. 

This is a known issue that occurs because the mailbox is not available to WebDAV until a client logs on to that mailbox.  Additionally this problem is documented in the following article:

839422    When you try to log on to an Exchange 2000 or an Exchange 2003 mailbox by using a WebDAV program, you receive a 401 status code in Internet Explorer
https://support.microsoft.com/default.aspx?scid=kb;EN-US;839422

For this issue the following options are different approaches that can be used to workaround this issue.  I wanted to get them combined and noted here for reference, since it didn't seem like there was a lot of information available to specifically address this issue:

  • After Creating the mailbox send a welcome message to the new mailbox, this will force the creation of the mailbox and you will be able to use WebDAV against the mailbox (Although the article above states that you cannot)
  • Manually log into the mailboxes after they are created (Not very practical if you are creating a lot of mailboxes at one)
  • Use either MAPI or CDO 1.21 to logon to those mailboxes BEFORE we use our WebDAV code to access that same mailbox.  Note: MAPI development needs to be done in VC++ but CDO 1.21 can be done in either VC++ or VB or VBScript.
  • Do a simple GET request (non-WebDAV) to the root of the newly created mailbox while NOT specifying the translate header to true.  This will also force the creation of the mailbox with just the HTTP GET request.

Related information:

A special thanks to Dan Bagley who blogs at https://blogs.msdn.com/webdav_101/ and has some good information on WebDAV and messaging development.

Knowledge base articles:

195662    How to log on to Exchange with the ProfileInfo parameter
https://support.microsoft.com/default.aspx?scid=kb;EN-US;195662
180597 How To Get the Name of the Profile you Logged On With
https://support.microsoft.com/default.aspx?scid=kb;EN-US;180597

MSDN references:

CDO 1.21 Session logon method:
https://msdn2.microsoft.com/en-us/library/ms526377.aspx
CDO 1.21 GetDefaultFolder method:
https://msdn2.microsoft.com/en-us/library/ms526181.aspx
MAPILogonEx documentation:
https://msdn2.microsoft.com/en-us/library/ms529409.aspx

-Jeff