我的任务是将mHtml嵌入到电子邮件体中。问题是mhtml不是一个普通的html文件,所以我不能将它直接嵌入到电子邮件中。
如何将mhtml转换为html文件?
谢谢
发布于 2016-05-12 16:33:45
我在这个链接上找到了解决方案:
原(死)联
解决方案是提取MHTML中编码为Base64的HTML。
var decoded_text = new StringBuilder();
using (var reader = new StreamReader(mhtFile))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line != "Content-Transfer-Encoding: base64") continue;
reader.ReadLine(); //chew up the blank line
while ((line = reader.ReadLine()) != String.Empty)
if (line != null)
decoded_text.Append(
Encoding.UTF8.GetString(
Convert.FromBase64String(line)));
break;
}
}发布于 2018-12-18 19:29:20
当html中没有对话框字母(例如ěščřžáíé-捷克字符或其他2个字节字符)时,接受的解决方案工作得很好。如果该字符的第一个字节位于变量"line“的末尾,第二个字节位于下一个字节的开头,则html结果中显示的字符不可读。
var base64_text = new StringBuilder();
using (var reader = new StreamReader(mhtFile))
{
while (!reader.EndOfStream)
{
var line = reader.ReadLine();
if (line != "Content-Transfer-Encoding: base64") continue;
reader.ReadLine(); //chew up the blank line
while ((line = reader.ReadLine()) != String.Empty)
if (line != null)
base64_text.Append(line);
break;
}
return Encoding.UTF8.GetString(Convert.FromBase64String(base64_text.ToString()));
}发布于 2016-05-12 16:40:29
我在一个文本编辑器(notepad++)中打开了这个页面中的notepad++,文件中显示的是完整的HTML。你必须通过所有的CSS向下滚动。我只会创建一些东西来从文件中提取HTML文本,而不是处理base64数据(如果某些东西不能正常工作的话,对我来说太混乱了)。
https://stackoverflow.com/questions/37192702
复制相似问题