简体   繁体   English

使用正确的编码向使用 Outlook 的人发送特殊字符

[英]using the correct encoding for sending special characters to people using outlook

I was wondering what encoding format i should be using to send special characters in emails to people using outlook.我想知道我应该使用什么编码格式来向使用 Outlook 的人发送电子邮件中的特殊字符。 I have done my own research and came accross ways to do things but none worked for me.我已经完成了自己的研究并遇到了做事的方法,但没有一种对我有用。 I checked outlook and it seems that by default, it is using Western European (Windows) format and is therefore using Windows-1252 Encoding (if what i searched and understood is correct).我检查了 Outlook,似乎默认情况下,它使用西欧 (Windows) 格式,因此使用 Windows-1252 编码(如果我搜索和理解的内容是正确的)。 However, when i tried to convert from unicode in C# to the Windows-1252 encoding, my outlook is still not recognising the special characters to be legitimate.但是,当我尝试从 C# 中的 unicode 转换为 Windows-1252 编码时,我的 Outlook 仍然无法识别特殊字符是合法的。 Eg below some random person's name:例如在一些随机人的名字下面:

expected result: Mr Moné Rêve预期结果: Moné Rêve 先生

actual result (wrong): Mr Moné Rêve实际结果(错误): MonéRêve 先生

Can anyone help me on what approach i should take to make the above correct.任何人都可以帮助我了解我应该采取什么方法来使上述正确。

My code:我的代码:

string Fullname = "Mr Moné Rêve";
Encoding unicode = new UnicodeEncoding(); 
Encoding win1252 = Encoding.GetEncoding(1252); 

byte[] input = unicode.GetBytes(Fullname);      
byte[] output = Encoding.Convert(unicode, win1252, input);

string result = win1252.GetString(output);  

There is no "Correct" encoding.没有“正确”编码。 You should specify the charset in the HTML.您应该在 HTML 中指定字符集。

This is taken from an email that I have received (you can get the source from an email using for instance outlook):这是从我收到的一封电子邮件中获取的(您可以使用例如 Outlook 从电子邮件中获取源):

<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">

When you set an encoding on the document you have to specify what encoding you use, otherwise the receiver won't know which one you used.当您在文档上设置编码时,您必须指定您使用的编码,否则接收者将不知道您使用的是哪种编码。 The declaration of the encoding can be read with whatever encoding you wish to use, thus the encoding can be read without knowing the encoding.可以使用您希望使用的任何编码来读取编码的声明,因此可以在不知道编码的情况下读取编码。

Read this about encodings and how they work: http://www.joelonsoftware.com/printerFriendly/articles/Unicode.html阅读有关编码及其工作原理的内容: http : //www.joelonsoftware.com/printerFriendly/articles/Unicode.html

最后,我去检查字符串中的特殊字符并将特殊字符更改为它们的等效代码,例如 é 变为&#233;

The best way is to convert them to their HTML entities.最好的方法是将它们转换为它们的 HTML 实体。 here is a tool called HTML Special Character Converter , it will help you convert special characters to their HTML entities width just one click.这是一个名为HTML 特殊字符转换器的工具,它可以帮助您将特殊字符转换为其 HTML 实体宽度,只需单击一下。

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

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