【问题标题】:Retrieve plain text body from email从电子邮件中检索纯文本正文
【发布时间】:2020-11-18 14:27:47
【问题描述】:

现在我使用此代码从 Exchange 2010 检索电子邮件正文:

i.Load(New PropertySet(BasePropertySet.IdOnly, ItemSchema.Body))
Dim strEmailBodyLines() As String = Split(i.Body.Text, vbCrLf)

不幸的是,我收到了一个 HTML 响应,但我只想要一个数组(每一行)中的正文中的纯文本。如果我将 ItemSchema.Body 替换为 ItemSchema.Textbody ,则会收到错误消息,它在 Exchange 2013 及更高版本上受支持。

谁能告诉我如何获取纯文本正文?

【问题讨论】:

    标签: visual-studio basic exchange-server-2010


    【解决方案1】:

    我知道相同的 C# 代码,您可以将其转换为 VB:

    // Create empty mail object for holding email details
    EmailMessage mail;
    
    // Bind properties from acual email message to mail object 
    mail = (EmailMessage)Item.Bind(_service, new ItemId(MessageUID));
    PropertySet propSet = new PropertySet(BasePropertySet.IdOnly);
    
    // Convert the email body to plain text from HTML
    PropertySet propertySets = new PropertySet(BasePropertySet.FirstClassProperties)
    {
        RequestedBodyType = Microsoft.Exchange.WebServices.Data.BodyType.Text
    };
    
    mail.Load(propertySets);
    

    【讨论】:

    • 谢谢。我将使用 VB 代码对此进行测试。
    猜你喜欢
    • 2015-04-10
    • 2012-01-03
    • 1970-01-01
    • 1970-01-01
    • 2012-06-14
    • 1970-01-01
    • 2012-11-18
    • 2017-03-07
    • 1970-01-01
    相关资源
    最近更新 更多