使用正确的编码向使用 Outlook 的用户发送特殊字符
我想知道应该使用什么编码格式将电子邮件中的特殊字符发送给使用 Outlook 的人。我自己做了研究,也找到了做事的方法,但没有一个对我有用。我检查了 Outlook,默认情况下它使用西欧 (Windows) 格式,因此使用 Windows-1252 编码(如果我搜索和理解的内容是正确的)。但是,当我尝试从 C# 中的 unicode 转换为 Windows-1252 编码时,我的 Outlook 仍然无法识别特殊字符是合法的。例如,下面是一些随机人的名字:
预期结果:Mr Moné Rêve
实际结果(错误):Mr Moné Rêve
任何人都可以帮助我,我应该采取什么方法来实现以上正确。
我的代码:
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);
I was wondering what encoding format i should be using to send special characters in emails to people using 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). 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. E.g below some random person's name:
expected result: Mr Moné Rêve
actual result (wrong): Mr 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);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
不存在“正确”的编码。您应该在 HTML 中指定字符集。
这是取自我收到的一封电子邮件(您可以使用 Outlook 等从电子邮件中获取源代码):
当您在文档上设置编码时,您必须指定您使用的编码,否则接收者将不知道哪种编码你用过的一个。可以使用您希望使用的任何编码来读取编码的声明,因此可以在不知道编码的情况下读取编码。
阅读有关编码及其工作原理的内容:http://www.joelonsoftware.com/printerFriendly/文章/Unicode.html
There is no "Correct" encoding. You should specify the charset in the HTML.
This is taken from an email that I have received (you can get the source from an email using for instance outlook):
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
最后,我检查了字符串中的特殊字符,并将特殊字符更改为其等效代码,例如 é 变为
é
In the end, i went for checking for special characters in my string and changing special characters into their code equivalent e.g é becomes
é
最好的方法是将它们转换为 HTML 实体。这是一个名为 HTML 的工具
特殊字符转换器,只需单击一下即可帮助您将特殊字符转换为其 HTML 实体宽度。
The best way is to convert them to their HTML entities. here is a tool called HTML
Special Character Converter, it will help you convert special characters to their HTML entities width just one click.