如何将电子邮件边界作为扩展属性添加到DefaultExtendedPropertySet.InternetHeaders属性集

时间:2014-02-05 14:18:20

标签: c# exchange-server exchangewebservices

我希望在电子邮件中添加唯一的故障单ID,以便我可以看到哪个故障单属于该电子邮件。现在的想法是使用电子邮件边界。这怎么样?我很困惑这应该如何工作,甚至可以工作......现在我正在使用EWS发送这样的电子邮件:

EmailMessage email = new EmailMessage(service);
email.Subject = "Test from c#";
email.Body = new MessageBody("This is the first email I've sent by using the EWS Managed Api");
email.Send();

如何为此代码添加电子邮件边界?我试过这样的事情:

ExtendedPropertyDefinition ticketId = new ExtendedPropertyDefinition(DefaultExtendedPropertySet.InternetHeaders, "boundary := ticket-123", MapiPropertyType.String);
email.SetExtendedProperty(ticketId, "ID-12345678");

但这不起作用。提前谢谢!

1 个答案:

答案 0 :(得分:1)

  1. 您无法在标题中指定=字符。
  2. 您不应在标题中包含空格。
  3. 标题中没有边界。
  4. 你不应该使用边界。
  5. 正确的代码应如下所示:

    ExtendedPropertyDefinition ticketId = new ExtendedPropertyDefinition(
        DefaultExtendedPropertySet.InternetHeaders, "ticket-id", MapiPropertyType.String);
    email.SetExtendedProperty(ticketId, "ID-12345678");
    

    检查获取故障单ID的代码应如下所示:

    string ticketId = null;
    InternetMessageHeader ticketHeader =
        message.InternetMessageHeaders.Find("ticket-id");
    if (ticketHeader != null)
        ticketId = ticketHeader.Value;
    if (!string.IsNullOrEmpty(ticketId)) {
        // TODO: Do something with the ticket ID
    }