Hi,
I have some code that is reading through mailboxes and extracting in-box, Sent Items and Deleted Items data. In relation to Sent Items I am particularly interested in identifying how many people the user sent emails to. Initial versions of the application just read the message.ToRecipients collection. This gave me the individual email addresses the user sent emails tom but I need to be more accurate and also work out if the recipient is a group. I inserted the MSDN example code for group expansion and this seemed to be working fine and I was getting the groups expanded out to their individual member email addresses. I have noticed however that we have a couple of groups that are hidden from the normal lists and these two do not expand.
When I checked the code I found that the address.MailboxType was coming back as null?
I then decided that I couldn't test for a group using:
if(message.ToRecipients[o].MailboxType == MailboxType.PublicGroup
|| message.ToRecipients[o].MailboxType == MailboxType.ContactGroup
|| message.ToRecipients[o].MailboxType == MailboxType.PublicFolder
)
So although it's messy I would assume all email addresses being processed are groups and when I then try and expand it and get an error I therefore assume it is a single mail address.
This doesn't work either as the group still doesn't expand and throws the same error as a single mail address so to all intents and purposes it appears to all the World as though it is a single mail address. Is this a bug in the EWS Managed API?
This is the full block of code:
if (message.ToRecipients == null || message.ToRecipients.Count == 0)
{
//Do nowt!
}
else
{
for (o = 0; o <= message.ToRecipients.Count - 1; o++)
{
NumRetries = 0;
try
{
{
foreach (EmailAddress address in grp.Members)
{
EmailTo tr = new EmailTo();
tr.ToEmailAddress = ConvertLEDN(address);
if(paramCN==null)
tr.AddRecord(0,false, d.DataExtractTableID,ref cn);
else
tr.AddRecord(0, false, d.DataExtractTableID, ref paramCN);
}
}
else
{
EmailTo tr = new EmailTo();
tr.ToEmailAddress = ConvertLEDN(message.ToRecipients[o].Address);
if (paramCN == null)
tr.AddRecord(0, false, d.DataExtractTableID, ref cn);
else
tr.AddRecord(0, false, d.DataExtractTableID, ref paramCN);
}
catch (Exception ex)
{
if(ex.Message == "No results were found.")
{
EmailTo tr = new EmailTo();
tr.ToEmailAddress = ConvertLEDN(message.ToRecipients[o].Address);
if(paramCN == null)
tr.AddRecord(0, false, d.DataExtractTableID, ref cn);
else
tr.AddRecord(0, false, d.DataExtractTableID, ref paramCN);
}
else
{
timer1.Enabled = true;
int c = 0;
do
{
c++;
if (c % 1000 == 0)
{
Application.DoEvents();
}
NumRetries++;
{
goto TryAgain2;
}
else
{
string msg = "Last error message was:" + Common.NNL + ex.Message + Common.NNL + "Press Yes to try again." + Common.NL + "Press No to save the data file and end the program.";
Environment.Exit(0);
else
goto TryAgain2;
} // if(ex.Message== "No results were found.")
} // End of Catch block
} // End of for (o = 0; o <= message.ToRecipients.Count - 1; o++)
Siv
Graham Sivill - Martley, Worcester. UK