使用 C#.Net 将名片发送到 Outlook

发布于 2024-12-13 15:09:14 字数 1071 浏览 2 评论 0原文

我有一个特定要求,即使用 C#.Net 将用户联系方式作为名片发送到 Outlook,它工作正常并将名片发送到 Outlook,但是当用户名采用 unicode 格式时会遇到问题。

样本1:
- 用户名:疯狂
- 它工作完美,能够在 Outlook 上查看用户名,没有任何问题。

Sample-2:
- 用户名:Müller
- 它发送名片,但在 Outlook 上显示为“Müller”。

使用的逻辑是:

  1. 详细信息将写入.vcf 文件(文本文件)中,
  2. 该文件将附加在邮件中。

代码示例
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:

  1. details will be written into the .vcf file (text file)
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦忆晨望 2024-12-20 15:09:14

您可以在此处查看 .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.

一杯敬自由 2024-12-20 15:09:14

您需要为具有 unicode 字符的字段指定字符集,

CHARSET=utf-8

例如:

N;CHARSET=utf-8:Müller

You need to specify charset for field with unicode characters with

CHARSET=utf-8

For example:

N;CHARSET=utf-8:Müller
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文