Checking mail using Outlook MailItem and Exchange 2003 very slow

S

Sam Tagney

I am using Visual Studio .NET C# to check incoming mail using the
Outlook.dll v.11 through .NET Interop, parse the email and then send
it back out.

Everything was working fine when we were running Exchange Server 5,
but when we upgraded to Exchange 2003 it now takes up to 30 minutes
for the program to recognize that new MailItems have arrived, where it
used to take around 3 minutes max. The funny thing is that I can sit
on another machine with Outlook 2003 running the same user profile and
the new mail items appear right away. The other funny thing is that
sometimes it does pickup the new MailItem after about 5 minutes, but
95% of the time it takes 30 minutes or more. I don't know if there is
a setting in Exchange 2003 that we need to set, or maybe a registry
setting on the client. I have found nothing on the internet about
this.

Here is the C# code I use to check and send mail:

static void HandleMessages(Outlook.MAPIFolder ibox)
{
try
{
LogMessage("Checking for new messages!", true, false);

Outlook.Items Items = ibox.Items;
Outlook.MailItem m = (Outlook.MailItem)Items.GetFirst();
while (null != m)
{
if(m.UnRead==true)
{
Outlook.MailItem g = (Outlook.MailItem)oApp.CreateItem
(Outlook.OlItemType.olMailItem);
string osubj;
string cs,gs;

g.Body = m.Body;
if(g!=null)
{
// fetch recipeints list from email message
// parse subject line

osubj = (string) m.Subject;
if (osubj != null)
{
osubj = osubj.Trim();
string[] alist = osubj.Split(new Char[] {'|'},50);

// empty current forward message subject

foreach(string cmd in alist)
{
if (cmd != "")
{
cs = cmd.Trim().Substring(0,2).Trim();
gs = cmd.Trim().Substring(3).Trim();
if(cs=="su")
{
g.Subject = gs;
}
else if(cs=="to")
{
g.Recipients.Add(gs);
}
else if(cs=="cc")
{
g.Recipients.Add(gs);
}
}
}

int rcount = (int)g.Recipients.Count;
if(rcount>0)
{
LogMessage("Email Succussfully Moved (" +
(string)g.Subject + ")", true, true);
g.Send();
}
else
{
LogMessage("Missing Recipients Email Address (" +
(string)g.Subject + ")", true, true);
}
}
}
else
{
LogMessage("Could not move email", true, true);
}
g = null;
m.UnRead = false;

} // if(Unread = true){...}
m = (Outlook.MailItem)Items.GetNext();

} //For loop
ibox = null;
}
catch(System.Runtime.InteropServices.COMException ce)
{
LogMessage(ce.Message, true, true);
}
catch(System.Exception e)
{
LogMessage(e.Message, true, true);
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top