1

合并两个 EmailMessage 的正确方法是什么?我试过以下:

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

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

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

4

1 回答 1

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()
于 2013-04-03T07:51:36.183 回答