FindFirstMailbox takes over 30 seconds

mcbsys
Posts: 36
Joined: Wed Jan 04, 2006 10:19 pm

FindFirstMailbox takes over 30 seconds

Postby mcbsys » Fri Nov 05, 2010 3:25 am

Hi,

I'm trying to get familiar with the ME API with a simple example: retrieve the first mailbox in the first post office.

I'm using ME Standard 4.26. I added one post office and two mailboxes (not counting Postmaster) via the MMC.

I'm using the .Net MailEnable.Admin.dll version 1.0.2447.28179.

I've created a simple form in a Visual Web Developer 2008 project (actually using Visual WebGui).

Code: Select all

Imports MailEnable.Administration

Public Class Form1

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim lResult As Long
        Dim oPostOffice As New MailEnable.Administration.Postoffice
        Dim oMailBox As New MailEnable.Administration.Mailbox

        oPostOffice.Account = ""
        oPostOffice.Name = ""
        lResult = oPostOffice.FindFirstPostoffice()
        If lResult = 0 Then
            lblPostOffice.Text = "No post office found."
        Else
            lblPostOffice.Text = oPostOffice.Name
            With oMailBox
                .Postoffice = oPostOffice.Name
                .Mailbox = ""
                .RedirectAddress = ""
                .RedirectStatus = -1
                .Status = -1
                .Size = -1
                .Limit = -1
                lResult = .FindFirstMailbox() 'This line takes 30+ seconds
                If lResult = 0 Then
                    lblMailbox.Text = "Failed to get first mailbox."
                Else
                    lblMailbox.Text = .Mailbox
                    lblEmailAddress.Text = .RedirectAddress
                End If
            End With
        End If
    End Sub

End Class

When I press the button, it goes to the .FindFirstMailbox() line in a fraction of a second, then it takes over 30 seconds to execute .FindFirstMailbox, then it completes. The data is correct (shows Postmaster mailbox).

What am I missing? Why does FindFirstMailbox take so long?

Thanks,

Mark Berry
MCB Systems

Admin
Site Admin
Posts: 785
Joined: Mon Jun 10, 2002 6:31 pm
Location: Melbourne, Victoria, Australia

Re: FindFirstMailbox takes over 30 seconds

Postby Admin » Fri Nov 05, 2010 4:38 am

Hi,

If this is a large mailbox, and the current quota usage details are out of date, it is likely trying to index the mailbox and calculate quota. A way around this is to change the value of the Size property for oMailbox. eg.

Use -1 as the normal wildcard which will get usage
Use -2 to not return the current disk usage if there is no quota set on a mailbox
Use -3 to just return last calculated usage
Use -4 to not get any mailbox usage at all

So unless you are needing to get the current disk usage for a mailbox, always use -4.

mcbsys
Posts: 36
Joined: Wed Jan 04, 2006 10:19 pm

Re: FindFirstMailbox takes over 30 seconds

Postby mcbsys » Fri Nov 05, 2010 6:38 am

Thanks for the reply.

I just installed ME today; the mailboxes are empty. However. changing to oMailBox.Size = -4 solved the problem!

I'm still unclear on how to do these searches. According to the API doc, "So if you wish to iterate through all the items in the class (by using FindNext), then just assign an empty string to the string properties, and a -1 to the long values." However some Long values can in fact be -1. You've mentioned special values for Size. What about Limit? If I specify Limit = -1, am I only searching for mailboxes that do not have a quota? How do I search all Mailboxes?

The other point of confusion is which fields must be specified when searching. The doc states, "But not all properties can be used for this pattern matching, so check with the class description to see what you can use." I did find where the Postoffice class can be searched by Name and Account. But most classes, including Mailbox, don't list any searchable fields. Does that mean I must specify all fields with empty/-1/-2/-3/-4 values?

Thanks again for your help,

Mark Berry
MCB Systems

Admin
Site Admin
Posts: 785
Joined: Mon Jun 10, 2002 6:31 pm
Location: Melbourne, Victoria, Australia

Re: FindFirstMailbox takes over 30 seconds

Postby Admin » Mon Nov 08, 2010 10:19 am

Hi,

All the classes have at least one searchable field (look under the Wildcard column in the .NET API docs for this). The mailbox does have the mailbox name as searchable, but it will ignore the other fields (you must supply the postoffice name though). If you are using FindFirst/Next it will go through all the mailboxes for a postoffice, since the postoffice is required. You will still need to set all non-used properties to either empty or -1, since for example, if you don't set -1 it will default to 0 and may be used as a search criteria in a function.

mcbsys
Posts: 36
Joined: Wed Jan 04, 2006 10:19 pm

Re: FindFirstMailbox takes over 30 seconds

Postby mcbsys » Tue Nov 09, 2010 1:37 am

Thanks for your reply.

I do see the "wildcard" column in the API doc, thanks. However, I must be missing something.

First you say the mailbox search will "ignore the other fields" besides the wildcard, Mailbox.

Then you say if you don't set the non-used properties to empty or -1, they may be used as a search criteria in a function.

So which is it: it ignores fields besides the wildcard field (implying that I don't have to set any other properties), or it filters on the other fields (implying that they are not ignored)? It seems from the examples it's the latter.

Maybe the wildcard is used only with .GetMailbox, whereas the other criteria are always used as a filter, whether using .GetMailbox or .FindFirstMailbox and .FindNextMailbox?

I have now graduated from using .FindFirstMailbox, which is working fine with the .Size = -4, to trying .FindNextMailbox, which takes about 60 seconds per mailbox, almost like it's reaching a 60-second timeout. So my test post office with Postmaster plus two mailboxes takes over two minutes to list the three mailboxes. NOW what am I doing wrong?

Code: Select all

        sPostOffice = ListBoxPostOffices.SelectedItem

        With oMailBox
            .Postoffice = sPostOffice
            .Mailbox = ""
            .RedirectAddress = ""
            .RedirectStatus = -1
            .Status = -1
            'See http://forum.mailenable.com/viewtopic.php?f=4&t=21193
            .Size = -4 '-4 to not get any mailbox usage at all
            .Limit = -1
            lResult = .FindFirstMailbox() 'works instantly
            If lResult = 0 Then
                ListViewUsers.Items.Add("No mailboxes found matching filter.")
            Else
                Do While lResult = 1
                    objListViewItem = ListViewUsers.Items.Add(.Mailbox)
                    objListViewItem.SubItems.Add(.RedirectAddress)
                    .Mailbox = ""
                    .RedirectAddress = ""
                    .RedirectStatus = -1
                    .Status = -1
                    .Size = -4
                    .Limit = -1
                    lResult = oMailBox.FindNextMailbox() 'takes about 1 minute per mailbox
                Loop
            End If
        End With

Thanks for your help,

Mark Berry
MCB Systems

mcbsys
Posts: 36
Joined: Wed Jan 04, 2006 10:19 pm

Re: FindFirstMailbox takes over 30 seconds

Postby mcbsys » Tue Nov 09, 2010 10:55 pm

Okay I think I figured out the delay issue.

I am running Visual Web Developer and MailEnable on the same Windows 7 development machine.

I ran Sysinternals' Process Monitor and discovered that .FindNextMailBox tries to write to "C:\Program Files\Mail Enable\Postoffices\TestPO\MAILROOT\Bob\_index.blk", but access is denied. Not sure why/how it eventually succeeds, but the delay is due to lots of ACCESS DENIED attempts.

So for development, I have to run Visual Studio as Administrator so it can access the MailEnable data. Then there is no delay.

For deployment to Server 2008 R2, I found I could set my app to use the MailEnableAppPool, which runs as the IME_ADMIN user. For Visual WebGUI to run, I had to change the MailEnableAppPool to Allow 32-bit Applications, but then it worked, and the standard web interface to MailEnable seems to be working fine.

I still need to understand the MailEnable API's searching/filtering approach better...

Mark Berry
MCB Systems

Who is online

Users browsing this forum: No registered users and 1 guest