我需要使用.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 :添加了发送电子邮件的完整代码
答案 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
标记,并且似乎需要LATIN1
或iso-8859-1
个字符集,而不是utf-8
为这些指定。
答案 1 :(得分:0)