2

I need to send e-mails to iPhone users with .vcf files for adding contacts. The problem is that contact name has umlaut symbols and they displays incorrectly. Also I noticed that if I send the same text in the body of email or open composed vcf file in notepad the symbols displays correctly.

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 the same text in the body

Can someone please help me?

UPDATE: Sorry, have to edit code sample, I've accidentally submit the wrong one.

UPDATE #2: It looks like it is not only iPhone problem, Outlook also does not recognize umlauts.

UPDATE #3: Added full code for sending e-mail

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
pas_art
  • 99
  • 10

2 Answers2

1

Try changing to:

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

Just from reading elsewhere - looks like the format needs this CHARSET tag on each field, and seems that either LATIN1 or iso-8859-1 character sets, rather than utf-8 need to be specified for these.

Chris Ballard
  • 3,771
  • 4
  • 28
  • 40
  • unfortunately, neither of this charsets are working, still incorrect symbols in contact – pas_art Mar 19 '14 at 13:39
  • @ChrisBallard I don't see why you could not go with UTF-8 instead of Latin1. `Ä` **is** part of unicode: `U+00C4`. – ANeves Mar 19 '14 at 14:54
1

Try to change

VERSION:2.1\r\n

to

VERSION:3.0\r\n

After that you don't need CHARSET-Tags for fields with umlauts, it should work as expected.

Saqib Saud
  • 2,799
  • 2
  • 27
  • 41