I'm writing an Add-In for Outlook 2010 that should get the total number of people the recieving the email.

I can get the email property fairly easily with the following code:

<!-- language: lang-vb -->
Dim mailItem As MailItem
mailItem = Globals.ThisAddIn.Application.ActiveInspector.CurrentItem

MailItem exposes some properties like:

However, if the email is going out to a contact group (formerly distribution lists), mailItem.Recipients.Count will only return a value of 1, even though multiple people will get the email.

Is there a way to query the total number of recipients within a contact group?

On some level it has to be possible, because Outlook will even do some of it for you:

RecipientCount

Loop through all recipients in the MailItem.Recipients collection. For each recipient if the Recipient.AddressEntry property is not null, read the AddressEntry.Members property (returns AddressList object). If it is not null, recursively process each member of the list.

Like this:

<!-- language: lang-vb -->
Private Function GetAllRecipients(ByVal mailItem As MailItem) As List(Of String)
    Dim allRecipients As New List(Of String)
    For Each rec As Recipient In mailItem.Recipients
        If rec.AddressEntry IsNot Nothing Then
            AddAddressEntryMembers(allRecipients, rec.AddressEntry)
        End If
    Next
    Return allRecipients.Distinct.ToList()
End Function

Private Sub AddAddressEntryMembers(ByRef allRecipients As List(Of String),
                                   ByVal addressEntry As AddressEntry)
    If addressEntry.Members Is Nothing Then
        allRecipients.Add(addressEntry.Address)
    Else
        For Each member As AddressEntry In addressEntry.Members
            AddAddressEntryMembers(allRecipients, member)
        Next
    End If
End Sub

To get the number of recipients just call the return the list and call Count:

<!-- language: lang-vb -->
Dim totalRecipients = GetAllRecipients(mailItem).Count()