我有一个数据库应用程序,我允许用户将数据库中的个人下载到他们的Outlook联系人中。该程序在Windows机器上发送一个vCard到Outlook就好了。在iPad和iPhone电子邮件中,它会将vCard作为文本接收,而不是作为vCard附件。
BEGIN:VCARD VERSION:4.0 N; LANGUAGE = en-us:Doe; John ;; Mr。 FN:先生。 John Doe TITLE:ORG:ADR; HOME; PREF; ENCODING = QUOTED-PRINTABLE:;; TEL; WORK; VOICE:TEL; HOME; VOICE:TEL; CELL; VOICE:(999)555-1212 TEL; WORK; FAX:ADR; WORK; PREF; ENCODING = QUOTED-PRINTABLE:;; 123 Main St New York New York 10000 EMAIL; PREF; INTERNET:johndoe@gmail.com EMAIL; INTERNET:URL; WORK:NOTE:END:VCARD
我想知道我是不是正确地将vCard附加到邮件消息上,或者我是否需要更改将vCard字符串转换为iOS附件的方式。
我的iPhone用户使用iOS 7& 8。
我已就这个主题进行了大量研究,包括http://mobicontact.info/iphone/ios7-supports-vcard-vcf-download-at-last/,但我没有找到特定于我的方案的答案。
StringBuilder sb = new StringBuilder();
sb.Append("BEGIN:VCARD\r\n");
sb.Append("VERSION:4.0\r\n");
sb.AppendFormat("N;LANGUAGE=en-us:{0};{1};;{2};\r\n", member.LastName, member.FirstName, member.Prefix);
sb.AppendFormat("FN:{0} {1} {2}\r\n", member.Prefix, member.FirstName, member.LastName);
sb.AppendFormat("TITLE:{0}\r\n", member.Title);
sb.AppendFormat("ADR;HOME;PREF;ENCODING=QUOTED-PRINTABLE:;;{0}\r\n", member.Address + " " + member.City + " " + member.City + " " + member.ZIP);
sb.AppendFormat("TEL;WORK;VOICE:{0}\r\n", member.WorkPhone);
sb.AppendFormat("TEL;HOME;VOICE:{0}\r\n", member.HomePhone);
sb.AppendFormat("TEL;CELL;VOICE:{0}\r\n", member.CellPhone);
sb.AppendFormat("TEL;WORK;FAX:{0}\r\n", member.Fax);
sb.AppendFormat("EMAIL;PREF;INTERNET:{0}\r\n", member.WorkEmail);
sb.AppendFormat("EMAIL;INTERNET:{0}\r\n", member.HomeEmail);
sb.AppendFormat("URL;WORK:{0}\r\n", member.Website);
sb.AppendFormat("NOTE:{0}\r\n", member.Notes);
sb.Append("END:VCARD\r\n");
string cardContent = sb.ToString();
byte[] data = Encoding.ASCII.GetBytes(cardContent);
//save the data to a memory stream
MemoryStream ms = new MemoryStream(data);
Attachment newAttachment = new Attachment(ms, searchName.Name + ".vcf", "text/x-vcard");
ContentDisposition disposition = newAttachment.ContentDisposition;
disposition.CreationDate = DateTime.Now;
disposition.ModificationDate = DateTime.Now;
disposition.ReadDate = DateTime.Now;
disposition.DispositionType = DispositionTypeNames.Inline;
/Set up new email message
MailMessage mailMessage = new MailMessage();
mailMessage.Attachments.Add(newAttachment);
//Set up addresses
mailMessage.From = new MailAddress(emailAddress);
mailMessage.To.Add(emailAddress);
//Set up subject and body
mailMessage.Subject = "VCard: " + searchName.Name;
mailMessage.Body = "Attached is a VCard from the festival database";
SmtpClient smtp = new SmtpClient("cashub.palau.org");
smtp.Send(mailMessage);