使用 C#.Net 将名片发送到 Outlook
我有一个特定要求,即使用 C#.Net 将用户联系方式作为名片发送到 Outlook,它工作正常并将名片发送到 Outlook,但是当用户名采用 unicode 格式时会遇到问题。
样本1:
- 用户名:疯狂
- 它工作完美,能够在 Outlook 上查看用户名,没有任何问题。
Sample-2:
- 用户名:Müller
- 它发送名片,但在 Outlook 上显示为“Müller”。
使用的逻辑是:
- 详细信息将写入.vcf 文件(文本文件)中,
- 该文件将附加在邮件中。
代码示例:
System.IO.StreamWriter StreamWriter = new System.IO.StreamWriter(filePath);
StreamWriter.Write(msgStr);
StreamWriter.Close();
StreamWriter.Dispose();
附件 _mailAttachment = new Attachment(filePath);
_mailAttachment.ContentDisposition.Inline = true;
mailMessage.Attachments.Add(_mailAttachment);
client.Send(mailMessage);
甚至尝试在写入文件时对内容进行编码,但没有帮助。
任何帮助,我该如何解决 unicode 格式的问题?
Vcard 内容示例:
开始:VCARD
版本:2.1
N;CHARSET=UTF-8;LANGUAGE=en:Müller;亚历山大
FN;CHARSET=CHARSET=UTF-8;LANGUAGE=en:Müller Alexander
组织:CEF企业发展办公室
职位:服务经理
END:VCARD
但名字仍然显示为“Müller, Alexander”?
I have a specific requirement to send the user contact details as a Business Card to Outlook using C#.Net, it works perfectly and sends the Business Cards to Outlook however facing an issue when user name is in unicode format.
Sample-1:
- UserName : Crazy
- It works perfectly and able to view the user name without any issues on the outlook.
Sample-2:
- UserName : Müller
- It sends the business card however it is being displayed as "Müller" on the outlook.
the logic used is:
- details will be written into the .vcf file (text file)
- the file will be attached in the mail.
code sample:
System.IO.StreamWriter streamWriter = new System.IO.StreamWriter(filePath);
streamWriter.Write(msgStr);
streamWriter.Close();
streamWriter.Dispose();
Attachment _mailAttachment = new Attachment(filePath);
_mailAttachment.ContentDisposition.Inline = true;
mailMessage.Attachments.Add(_mailAttachment);
client.Send(mailMessage);
even tried to encode the content while writing into the file however does not help.
Any help, how can I fix the issue with the unicode formating?
Sample Vcard content:
BEGIN:VCARD
VERSION:2.1
N;CHARSET=UTF-8;LANGUAGE=en:Müller;Alexander
FN;CHARSET=CHARSET=UTF-8;LANGUAGE=en:Müller Alexander
ORG:CEF Corporate Development Office
TITLE:Service Manager
END:VCARD
but still the name is being displayed as "Müller, Alexander"?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以在此处查看 .Net vCard 生成库。它支持你正在尝试做的事情。另外,您必须记住,通常 vCard 文件必须编码为 ASCII,因此您可能必须转换为 ASCII(如 QUOTED-PRINTABLE)才能正常工作。
You might have a look at the .Net vCard generation library here. It supports what you are trying to do. Also, you have to remember that typically vCard files must be encoded as ASCII, so you'll probably have to convert to ASCII (like QUOTED-PRINTABLE) for it to work.
您需要为具有 unicode 字符的字段指定字符集,
例如:
You need to specify charset for field with unicode characters with
For example: