Threekill
Threekill

Reputation: 189

.Net EWS send mail to ContactGroup

I have created a contact group and when I send the name of the contact group as a recipient in EWS it give the following exception "One or more recipients are invalid."

I have been searching for an answer and there is not a lot of information of EWS contact group useage out there.

Any clues?

Upvotes: 0

Views: 430

Answers (1)

Threekill
Threekill

Reputation: 189

I did some research and found my answer. Here is the solution for anyone who needs it.

//Setup ContactGroup EmailAddress
EmailAddress emailAddress = new EmailAddress();
emailAddress.MailboxType = MailboxType.ContactGroup;                            
emailAddress.Id = ItemID;
message.ToRecipients.Add(emailAddress);

//You can get the ItemID with the following code.

// Instantiate the item view with the number of items to retrieve from the Contacts folder.
ItemView view = new ItemView(9999);

// Request the items in the Contacts folder that have the properties that you selected.
FindItemsResults contactItems = ExchangeService.FindItems(WellKnownFolderName.Contacts, view);

// Loop through all contacts 
foreach (Item item in contactItems)
{
    //Check to see if ContactGroup
    if (item is ContactGroup)
    {
        //Get the contact group
        ContactGroup contactGroup = item as ContactGroup;
    }
}

Upvotes: 1

Related Questions