.Net EWS向ContactGroup发送邮件

时间:2013-10-28 20:43:43

标签: .net exchangewebservices

我创建了一个联系人组,当我在EWS中将联系人组的名称作为收件人发送时,它会给出以下异常“一个或多个收件人无效”。

我一直在寻找答案,并没有很多关于EWS联络小组使用的信息。

任何线索?

1 个答案:

答案 0 :(得分:1)

我做了一些研究并找到了答案。对于任何需要它的人来说,这是一个解决方案。

//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;
    }
}