iPhone v-card中的变形金刚

时间:2014-03-19 12:34:28

标签: c# encode vcard vcf

我需要使用.vcf文件向iPhone用户发送电子邮件以添加联系人。问题是联系人姓名有变音符号并且显示不正确。 另外我注意到,如果我在电子邮件正文中发送相同的文本或在记事本中打开合成的vcf文件,则符号会正确显示。

public void SendEmail(string to, string subject, string body)
    {
        using (var message = new MailMessage())
        {
            message.To.Add(new MailAddress(to));
            message.Subject = subject;
            message.SubjectEncoding = Encoding.UTF8;
            message.BodyEncoding = Encoding.UTF8;
            message.HeadersEncoding = Encoding.UTF8;
            using (var stream = new MemoryStream(Encoding.UTF8.GetBytes(body)))
            {
                string attachamentName = string.Format("{0}.vcf", subject);
                Attachment attachment = new Attachment(stream, MediaTypeNames.Application.Octet) { Name = attachamentName };
                attachment.ContentDisposition.DispositionType = DispositionTypeNames.Attachment;
                message.Attachments.Add(attachment);

                using (var client = new SmtpClient())
                {
                    client.Send(message);
                }
            }
        }
    }

incorrect v-card http://clip2net.com/clip/m299434/1395230200-clip-46kb.jpg the same text in the body http://clip2net.com/clip/m299434/1395230423-clip-63kb.jpg

有人可以帮帮我吗?

更新:抱歉,我必须编辑代码示例,我不小心提交了错误的代码。

UPDATE#2 :看起来不仅是iPhone问题,Outlook也无法识别变音符号。

更新#3 :添加了发送电子邮件的完整代码

2 个答案:

答案 0 :(得分:1)

尝试更改为:

BEGIN:VCARD\r\nVERSION:2.1\r\nN;CHARSET=LATIN1:Fältskog;Agnetha\r\nFN;CHARSET=LATIN1:Agnetha Fältskog\r\nORG:\r\nTITLE:\r\nEND:VCARD

只是在其他地方阅读 - 看起来格式需要在每个字段上使用此CHARSET标记,并且似乎需要LATIN1iso-8859-1个字符集,而不是utf-8为这些指定。

答案 1 :(得分:0)

尝试更改

VERSION:2.1\r\n

VERSION:3.0\r\n

之后你不需要CHARSET-Tags for fields with umlauts, 它应该按预期工作。