【问题标题】:Merge two EmailMessage in C#在C#中合并两个EmailMessage
【发布时间】:2013-04-03 07:45:19
【问题描述】:

合并两个EmailMessage的正确方法是什么。我尝试了以下操作:

mergedMessage.Body.Text = message1.Body.Text + message2.Body.Text

但是它在合并的消息中创建了两个html标签,这是不正确的。

我应该解析message1.Body.Textmessage2.Body.Text并获取html的内容并复制到mergedMessage吗?

【问题讨论】:

  • Should I parse the message1.Body.Text and message2.Body.Text and fetch the content of html and copy to the mergedMessage? 是的。

标签: c# email system.net.mail


【解决方案1】:

你可以这样做 使用 System.Text.RegularExpressions;

const string HTML_TAG_PATTERN = "<.*?>";

static string StripHTML (this string inputString)
{
   return Regex.Replace 
     (inputString, HTML_TAG_PATTERN, string.Empty);
}


mergedMessage.Body.Text = message1.Body.Text.StripHTML()  + message2.Body.Text.StripHTML()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 2012-05-07
    • 1970-01-01
    • 2010-10-02
    • 2021-04-29
    • 1970-01-01
    相关资源
    最近更新 更多