EWS:在保存 EML 时将用户属性添加到 EML



在我的一些邮件中,我通过Outlook存储了一些用户属性...

item.UserProperties.Add("CustID", Outlook.OlUserPropertyType.olText)
item.UserProperties("CustID").Value = custID.ToString

在未安装Outlook的PC(服务器(上,我想将邮件下载为EML并存储用户属性(如"CustID"等(。

我保存 EML 的代码:

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    Dim service As New ExchangeService(ExchangeVersion.Exchange2013)
    service.Credentials = New WebCredentials("my@email.com", "mypsw")
    service.Url = New System.Uri("https://outlook.office365.com/EWS/Exchange.asmx")
    Dim entryID As String = "00000000C802F40668D27342B788D508E9210A67005DF9A7DEF7194A418C8515031D4262280000E00005DF9A7DEF7194A418C8515031D4262280002A9D18B320000"
    Dim id As New ItemId(Convert(service, "my@email.com", entryID))
    Dim email As EmailMessage = EmailMessage.Bind(service, id)
    Dim ps As PropertySet = New PropertySet(ItemSchema.MimeContent)
    email.Load(ps)
    Using fileStream = New IO.FileStream("D:sandbox_email_test.eml", IO.FileMode.Create)
        fileStream.Write(email.MimeContent.Content, 0, email.MimeContent.Content.Length)
    End Using
End Sub

Private Function Convert(service As ExchangeService, mailbox As String, entryID As String) As String
    Dim originalID As New AlternateId()
    originalID.Format = IdFormat.HexEntryId
    originalID.Mailbox = mailbox
    originalID.UniqueId = entryID 'EntryId retrieved from email in Outlook
    Dim altBase As AlternateIdBase = service.ConvertId(originalID, IdFormat.EwsId)
    Dim convertedID As AlternateId = DirectCast(altBase, AlternateId)
    Dim strConvertedID As String = convertedID.UniqueId
    Return strConvertedID
End Function

有没有办法在 EML 中存储用户属性?如果是,如果我双击 EML 以在 Outlook 中打开它,是否可以从 EML 中读回用户属性?

谢谢!

用户属性是 Mapi/Extended 属性,不包含在消息的 MimeStream 中。如果将属性添加为 X 标头,则它们将在 MimeSteam 中可用,否则最好将消息导出为 MSG 文件,这将为您提供所有 MAPI 属性的完全保真度。要导出为味精,您需要使用 Outlook,如果您需要自动化,可能需要查看赎回 http://www.dimastr.com/redemption/rdo_introduction.htm 之类的内容。

干杯幽谷

相关内容

  • 没有找到相关文章

最新更新