如何从Outlook Exchange Server(EWS)获取约会的约会正文文本,c#?

时间:2016-10-13 20:45:36

标签: c#

我正在尝试从Exchange服务器获取电子邮件正文以预约特定房间但未获得成功。通过互联网验证了所有博客,但没有任何帮助。以下是我尝试联系Exchange服务器以获取详细信息的代码:

方法A

service.GetUserAvailability
(
    attendees,
    new TimeWindow(twStart, twEnd),
    AvailabilityData.FreeBusy
).AttendeesAvailability[0].CalendarEvents;

方法B

public class MailItem
{
    public string From;
    public string[] Recipients;
    public string Subject;
    public string Body;
}

public static MailItem[] GetUnreadMailFromInbox(ExchangeService service, string address)
{
    // Address is the email address for an meeting room
    try
    {
        service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, address);
        FindItemsResults<Item> findResults = service.FindItems(WellKnownFolderName.Inbox, new ItemView(128));
        ServiceResponseCollection<GetItemResponse> items =
        service.BindToItems(findResults.Select(item => item.Id), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients));

        FindItemsResults<Item> findResults2 = service.FindItems(WellKnownFolderName.Calendar, new ItemView(128));
        ServiceResponseCollection<GetItemResponse> items2 =
        service.BindToItems(findResults2.Select(item2 => item2.Id), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.ToRecipients));

        return items.Select(item =>
        {
            return new MailItem()
            {
                From = address,
                Recipients = ((Microsoft.Exchange.WebServices.Data.EmailAddressCollection)item.Item[EmailMessageSchema.ToRecipients]).Select(recipient => recipient.Address).ToArray(),
                Subject = item.Item.Subject,
                Body = item.Item.Body.ToString(),
            };
        }).ToArray();
    }
    catch (Exception ex)
    {
        throw ex;
    }
}

我需要一个解决方案,用于从Exchange服务器获取约会的正文内容。

1 个答案:

答案 0 :(得分:1)

假设您已成功连接到Exchange服务并且只尝试检索约会正文部分,请尝试此操作。

尝试将EmailMessageSchema.Body添加到您的媒体资源中。

 service.BindToItems(findResults2.Select(item2 => item2.Id), new PropertySet(BasePropertySet.FirstClassProperties, EmailMessageSchema.From, EmailMessageSchema.Body, EmailMessageSchema.ToRecipients));