Problems deleting mailboxes using DeleteMailbox()

Problems deleting mailboxes using DeleteMailbox()

Post by Earl G Elliott I » Wed, 05 Jun 2002 01:03:30



I am having a problem trying to delete mailboxes from an Exchange 2000
server.  I go grab the user object using system.directoryservices and
use the IMailboxStore interface to try an delete the mailbox of the
user.  Deleting the user from AD gives me no problems at all.  When I
give the DeleteMailbox() command it gives me a Catastrophic Failure.
Specifically,

An unhandled exception of type
'System.Runtime.InteropServices.COMException' occurred in stiemail.dll

Additional information: Catastrophic failure

I've looked around a bunch of places and can't find any information.
Microsoft's examples on the subject dont work either.  If anyone has
any suggestions please let me know.  Need to try and get this working
soon.  The code that I am using is included below:

Public Sub deleteAccount(ByVal EmailID As String, ByVal LDAP As
String)

        Dim oRegistry As New STI.Libs.Registry(mConn)
        Dim oUser As IADsUser
        Dim oMailBox As CDOEXM.IMailboxStore
        Dim sDomName As String
        Dim sDomCtrl As String
        Dim aPath As Array
        Dim oTmp As Object
        Dim sLDAPConn As String
        Dim sHomeMDB As String

        sDomName = oRegistry.GetItemValue("Applications\PostOffice\Active
Directory\DomainName")

        'LDAP variable comes into .dll in format
<domainController>/<OU1>/<OUN>/<container1>

        sDomCtrl = sDomCtrl.Concat("DC=", sDomName.Replace(".",
",DC="))
        LDAP = LDAP.Remove(0, LDAP.IndexOf("/") + 1)
        aPath = Split(LDAP, "/")
        aPath.Reverse(aPath)

        For Each oTmp In aPath
            sLDAPConn = sLDAPConn.Concat(sLDAPConn, "OU=", oTmp, ",")
        Next

        sLDAPConn = "LDAP://" & sDomName & "/" & sLDAPConn & sDomCtrl

        Dim dirEntry As New
DirectoryServices.DirectoryEntry(sLDAPConn)
        Dim deUser As DirectoryServices.DirectoryEntry

        deUser = dirEntry.Children.Find("CN=" & EmailID)
        oUser = CType(deUser.NativeObject, IADsUser)
        oMailBox = CType(oUser, CDOEXM.IMailboxStore)

        oMailBox.DeleteMailbox()

        oUser.SetInfo()
        dirEntry.Children.Remove(deUser)
        deUser.CommitChanges()

Thanks,
Earl

 
 
 

Problems deleting mailboxes using DeleteMailbox()

Post by Siegfried Weber [MVP » Wed, 05 Jun 2002 09:02:30



Quote:

> I am having a problem trying to delete mailboxes from an Exchange 2000
> server.  I go grab the user object using system.directoryservices and
> use the IMailboxStore interface to try an delete the mailbox of the
> user.  Deleting the user from AD gives me no problems at all.  When I
> give the DeleteMailbox() command it gives me a Catastrophic Failure.
> Specifically,

[snip]

Try to delete the mailbox before deleting the user object in Active
Directory.

--
<Siegfried />

Development Lead,

Microsoft Most Valuable Professional (MVP) - Exchange Server
Co-author of "Professional CDO Programming", Wrox Press 1999

CDOLive LLC - The Microsoft Messaging and Collaboration Application Experts
http://www.cdolive.com

Please reply to the newsgroups so that others can benefit from the
discussion.
Questions by e-mail are discarded without further notice.

 
 
 

Problems deleting mailboxes using DeleteMailbox()

Post by Earl G Elliott I » Wed, 05 Jun 2002 22:18:05




> > I am having a problem trying to delete mailboxes from an Exchange 2000
> > server.  I go grab the user object using system.directoryservices and
> > use the IMailboxStore interface to try an delete the mailbox of the
> > user.  Deleting the user from AD gives me no problems at all.  When I
> > give the DeleteMailbox() command it gives me a Catastrophic Failure.
> > Specifically,

> [snip]

> Try to delete the mailbox before deleting the user object in Active
> Directory.

That is what I am doing now.

<excerpt from code>

        'get path
        deUser = dirEntry.Children.Find("CN=" & EmailID)

        'create IADSUser obj
        oUser = CType(deUser.NativeObject, IADsUser)

        'create Mailbox obj
        oMailBox = CType(oUser, CDOEXM.IMailboxStore)

        oMailBox.DeleteMailbox()         'remove mailbox

        oUser.SetInfo()                  'update account
        dirEntry.Children.Remove(deUser) 'remove user
        deUser.CommitChanges()           'commit changes

<end excerpt>

I have tried removing the user first as well.  If I do that the
DeleteMailbox() command executes, but the HomeMDB is "" because it has
lost its pointer to the object, and thus the mailbox is not removed.

Thx for the response.  Let me know if you can think of anything else.
I am sure it is something fairly simple that I am just missing.

Earl

Quote:

> --
> <Siegfried />

> Development Lead,

> Microsoft Most Valuable Professional (MVP) - Exchange Server
> Co-author of "Professional CDO Programming", Wrox Press 1999

> CDOLive LLC - The Microsoft Messaging and Collaboration Application Experts
> http://www.cdolive.com

> Please reply to the newsgroups so that others can benefit from the
> discussion.
> Questions by e-mail are discarded without further notice.

 
 
 

Problems deleting mailboxes using DeleteMailbox()

Post by Siegfried Weber [MVP » Wed, 05 Jun 2002 23:46:27



 [snip]

Quote:> I have tried removing the user first as well.  If I do that the
> DeleteMailbox() command executes, but the HomeMDB is "" because it has
> lost its pointer to the object, and thus the mailbox is not removed.

Ouch! I didn't see that you are doing it in the right order. Sorry!!

Quote:> Thx for the response.  Let me know if you can think of anything else.
> I am sure it is something fairly simple that I am just missing.

I'll see if I can come up with a simple WSH/VBScript to see if
DeleteMailbox() works at all. If so (and I assume it will) I'd say that the
import of CDOEXM into .NET might cause the problem.

--
<Siegfried />

Development Lead,

Microsoft Most Valuable Professional (MVP) - Exchange Server
Co-author of "Professional CDO Programming", Wrox Press 1999

CDOLive LLC - The Microsoft Messaging and Collaboration Application Experts
http://www.cdolive.com

Please reply to the newsgroups so that others can benefit from the
discussion.
Questions by e-mail are discarded without further notice.

 
 
 

Problems deleting mailboxes using DeleteMailbox()

Post by Earl G Elliott I » Fri, 07 Jun 2002 00:20:31




>  [snip]

> > I have tried removing the user first as well.  If I do that the
> > DeleteMailbox() command executes, but the HomeMDB is "" because it has
> > lost its pointer to the object, and thus the mailbox is not removed.

> Ouch! I didn't see that you are doing it in the right order. Sorry!!

> > Thx for the response.  Let me know if you can think of anything else.
> > I am sure it is something fairly simple that I am just missing.

> I'll see if I can come up with a simple WSH/VBScript to see if
> DeleteMailbox() works at all. If so (and I assume it will) I'd say that the
> import of CDOEXM into .NET might cause the problem.

Gak.  Ok.  Thanks for you help.

Earl

 
 
 

Problems deleting mailboxes using DeleteMailbox()

Post by Earl G Elliott I » Sat, 08 Jun 2002 00:16:07





> >  [snip]

> > I'll see if I can come up with a simple WSH/VBScript to see if
> > DeleteMailbox() works at all. If so (and I assume it will) I'd say that the
> > import of CDOEXM into .NET might cause the problem.

[snip]

Found something out.  I tried it in a VBScript file and the
catastrophic failure is actually :

Script:         C:\documents and settings\eelliott\desktop\deletemailbox.vbs
Line:           35
Char:           3
Error:          The action could not be completed because the Microsoft
Exchange Information Store service is unavailable.  Be sure the
service is running and you have network connectivity to the Microsoft
Exchange Server computer.

ID no:          c1041721
Microsoft CDO for Exchange Management

Code:           8000FFFF
Source:         (null)

This same script will work fine on the actual exchange server, but
will not work on my workstation.  Both machines are on a different
domain and I am assuming that is the problem.  (workstation on
sti-k12.com and exchange on devnet.sti-k12.com).  Is there some way to
get this to run from a remote station.  The code was adapted from a
post by BrianG that he was having a similar problem with.  Here is the
code:

call Deletemailbox("","","","","","","")

Sub DeleteMailbox(cn, servername, domainraw,ou,user,password, domain)
  Dim oUser
  Dim Elementnames
  Dim Element
  Dim objMailbox
  Dim objCDOPerson
  Dim strURL
  Dim iDSO, iOu
  Dim iLdapString

  Set iDSO = GetObject("LDAP:")
  iLdapString = "LDAP://devnet.sti-k12.com/OU=Students,OU=SchoolA,OU=District1,OU=StudentEmail,DC=devnet,DC=sti-k12,DC=com"

  'Connect to AD
  Set iOu = iDSO.OpenDSObject(iLdapString,

  'Get User object
  Set oUser = iOu.GetObject("User", "CN=CJohnny")

  'Create the CDO Person object
  Set objCDOPerson = CreateObject("CDO.Person")

  'Get the IMailBoxStore Interface
  Set objMailbox = objCDOPerson.GetInterface("IMailboxStore")

  'Set User to IMailBoxStore Interace
  Set objMailbox = oUser

  'Create Mailbox
  objMailbox.DeleteMailBox

  oUser.SetInfo

  msgbox "Done"

End Sub

Thx,
Earl

 
 
 

Problems deleting mailboxes using DeleteMailbox()

Post by Siegfried Weber [MVP » Sat, 08 Jun 2002 04:15:36


Sorry that I didn't get back to you earlier!!!


 [snip]

Quote:> This same script will work fine on the actual exchange server, but
> will not work on my workstation.  Both machines are on a different
> domain and I am assuming that is the problem.  (workstation on
> sti-k12.com and exchange on devnet.sti-k12.com).  Is there some way to
> get this to run from a remote station.

Yep. That's the problem. CDOEXM runs always under the security context of
the currently logged on user which means if this user doesn't have
appropriate permissions on the Exchange 2000 server in question your code
will fail. I am not aware of a workaround to run the code from the client.

Your best bet is to build a Webservice which runs on the Exchange 2000
machine with proper privileges and use the Webservice from your client
computer.

--
<Siegfried />

Development Lead,

Microsoft Most Valuable Professional (MVP) - Exchange Server
Co-author of "Professional CDO Programming", Wrox Press 1999

CDOLive LLC - The Microsoft Messaging and Collaboration Application Experts
http://www.cdolive.com

Please reply to the newsgroups so that others can benefit from the
discussion.
Questions by e-mail are discarded without further notice.

 
 
 

1. Problem using DAPIWrite to delete Exchange mailboxes

I have a customer with a problem with our application that occurs when DAPIWrite
is used to delete an Exchange mailbox.

Our attribute list looks like:

const TCHAR* DAPIAttrList = _T("Obj-Class,Directory Name,Obj-Container");

The value list for the attributes is:

DAPIValueList = "Mailbox," + ExchangeMailbox + "," + ExchangeContainer;

The function works, but after deleting the mailbox, and using Exchange
Administator, under Configuration, Server, <ServerName>, Private Information
Store, Mailbox Resources, the account that was deleted is still there taking
space in the Private Information Store.  Clicking on the account from this screen
produces the error:

"The object cannot be found in the directory. This may be because replication has
not completed. Microsoft Exchange Directory  ID no: c1010aae"

The customer does not want to run the eseutil utility, out of concern that
something may become damaged.

We've been unable to reproduce this behavior on our Exchange servers, and don't
have any other customers with this problem, so this problem may be specific to
particular installation.

So, my questions are:

- Are there any Exchange server settings that could cause the deleted mailbox
entries to not completely remove all traces of themself ?
- What other mechanism can I used to delete the Exchange mailbox ?  ADSI
functions ?  I plan to convert to using ADSI soon, but would rather know why the
DAPI function is not working.
- Is there any way to fix this problem without running eseutil.

In case anyone is wondering why I am not using BatchImport, that API is too
clumsy and makes lots of event log messages, that my customers would not stand
for.

Thanks for any replies

-kevin

2. Exchange 2000 on a NAS device

3. ADSI script help: DeleteMailbox is not removing the mailbox from info store

4. Help Help Help!!!Exchange Routing Wizard

5. Using CDO to Delete a mailbox in Excchange 2000

6. e-mail filter tools

7. Deleting Mailboxes Using Directory Import?

8. Exchange Security

9. using offline folders of a deleted mailbox

10. Using Tools / Directory Import to delete mailboxes

11. Deleting Mailboxes by using a .CSV

12. Problem with delete mail using Outlook clients

13. DeleteMailbox Method?