简体   繁体   English

纯文本到 Outlook email 中的 HTML 转换

[英]Plain text to HTML conversion in Outlook email

I am facing a situation to preserve the formatting of plain text email when displaying it as virtual plain text in C sharp.当我将纯文本 email显示为 C 锐利的虚拟纯文本时,我面临保留纯文本格式的情况。 This is done during receiving in Outlook 2007 using VSTO.这是在使用 VSTO 接收 Outlook 2007 期间完成的。 The code below does not do the job, instead it converts the body into Times New Roman;Font Size 10 and displays it to the user.下面的代码没有完成这项工作,而是将正文转换为 Times New Roman;Font Size 10 并将其显示给用户。

string Text = "<html><body><p style=\"font-family:consolas;font-size:88%;\">" + mailItem.Body+ "</p></body></html>";

mailItem.HTMLBody = Text;

mailItem.HTMLBody = Regex.Replace(mailItem.HTMLBody, "(ASA[a-z][a-z][0-9][0-9])", "<a href=\"http://stack.com/eg=$&\">$&</a>");

How can I rectify this problem?我该如何解决这个问题?

EDIT:编辑:

Input:输入:

ASAss87 ASAss87

ASAjj98 ASAjj98

this is test input这是测试输入

Output: Output:

ASAss87 ASAjj98 this is test input ASAss87 ASAjj98 这是测试输入

EDIT 2:编辑2:

Input:输入:

ASAss87 ASAss87

ASAjj98 ASAjj98

this is test input.

Output: Output:

ASAss87 ASAss87

ASAjj98 ASAjj98

   this is test input.

*Moves one or two spaces forward. *向前移动一到两个空格。 I am using tag.我正在使用标签。

Based on your feedback in the comments, try changing your first line to use Body instead of HTMLBody :根据您在评论中的反馈,尝试将您的第一行更改为使用Body而不是HTMLBody

string Text = "<html><body><p style=\"font-family:consolas;font-size:88%;\">" + mailItem.Body+ "</p></body></html>";

Edit: Since the plain text contains line-breaks, maybe you should use a <pre> tag instead of a <p > tag, to prevent it from putting everything on one line.编辑:由于纯文本包含换行符,也许您应该使用<pre>标记而不是<p > 标记,以防止它将所有内容放在一行上。

string Text = "<html><body><pre style=\"font-family:consolas;font-size:88%;\">" + mailItem.Body+ "</pre></body></html>";

Edit2: Alternatively, you can replace all line-breaks with <br> tags. Edit2:或者,您可以用<br>标签替换所有换行符。

string Text = "<html><body><p style=\"font-family:consolas;font-size:88%;\">" + mailItem.Body.Replace(Environment.NewLine,"<BR>") + "</p></body></html>";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM