在 C# 中读取电子邮件表单数据

Read Email Form Data in C#

我创建了一个 Outlook 自定义表单,填写并发送到我的收件箱。

现在,在我的代码中;

        ExchangeService exchange = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
        exchange.UseDefaultCredentials = true;
        exchange.AutodiscoverUrl("firstname.lastname@companyname.com.au", RedirectionUrlValidationCallback);

        TimeSpan ts = new TimeSpan(0, -1, 0, 0);
        DateTime date = DateTime.Now.Add(ts);
        SearchFilter.IsGreaterThanOrEqualTo filter = new SearchFilter.IsGreaterThanOrEqualTo(ItemSchema.DateTimeReceived, date);

        if (exchange != null)
        {
            Folder inbox = Folder.Bind(exchange, WellKnownFolderName.Inbox);
            SearchFilter sf = new SearchFilter.SearchFilterCollection(LogicalOperator.And, new SearchFilter.IsEqualTo(EmailMessageSchema.IsRead, false));
            ItemView view = new ItemView(1);
            FindItemsResults<Item> findResults = exchange.FindItems(WellKnownFolderName.Inbox, sf, view);

            foreach (Item item in findResults)
            {
                EmailMessage message = EmailMessage.Bind(exchange, item.Id);
                string messageBody = message.Body;

我可以获取主题、正文等,但如何读取自定义表单中的字段?

所以我在表单中有一个名为 textbox1 的字段。

提前致谢。

您需要了解您的自定义表单在 Outlook 中创建的 MAPI 属性 的详细信息。您可以使用 MFCMapi 或 Outlook Spy 等 Mapi 编辑器轻松找到它。知道 GUID、标签信息后,您只需定义它并告诉 EWS 给您 return 和 属性,例如很可能是

ExtendedPropertyDefinition CustomProperty = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.PublicStrings, "CustomPropertyName", MapiPropertyType.String);
PropertySet ItemPropSet = new PropertySet(BasePropertySet.FirstClassProperties);
ItemPropSet.Add(CustomProperty);
EmailMessage message = EmailMessage.Bind(exchange, item.Id,ItemPropSet);

另见 https://msdn.microsoft.com/en-us/library/office/dd633697(v=exchg.80).aspx

干杯 格伦