views:

2171

answers:

3

Hi all,

i am sending emails with the integrated System.Net.Mail

i do like

MailAddress abs = new System.Net.Mail.MailAddress("[email protected]", "Web Präsenz", System.Text.Encoding.UTF8);

when the E-Mail comes to Client the "ä" character is missing. seems like some encoding Problems.

anyone knows how to fix it?

+2  A: 

try adding these too:

message.BodyEncoding =  System.Text.Encoding.UTF8;
message.SubjectEncoding = System.Text.Encoding.UTF8;

It may also be a mail server issue. Try sending it to various e-mail address; POP3, WebMail, etc.

There some more info here, though you've probably already looked here:

http://msdn.microsoft.com/en-us/library/system.net.mail.smtpclient.aspx

craigmoliver
A: 

it is not body oder subject encoding. but it is encoding of the display name of the senders e-mail address.

:(

did you try it?
craigmoliver
+2  A: 

I just spent 5 hours debugging a similar problem, and the solution I found may be the solution to this problem also. Since no one has posted any other solutions I will contribute my findings.

There seem to be a subtle bug in the .NET2.0 Mail API which causes encoding of Recipient names in the mail headers to fail. This occurs if the To property (and possibly others) of the MailMessage instance is accessed before the message is sent.

The following example will cause the To header to be sent without encoding, causing at least my mail client to display the name as "??????...":

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("[email protected]", "ÆØÅ Unicode Name"));
message.Subject = "Subject";
message.Body = "Body";
Console.WriteLine(message.To[0]);
smtpClient.Send(message);

However moving the WriteLine below the send line, causes the To header to be correctly encoded:

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("[email protected]", "ÆØÅ Unicode Name"));
message.Subject = "Subject";
message.Body = "Body";
smtpClient.Send(message);
Console.WriteLine(message.To[0]);

I assume this bug will occur on the Cc and Bcc properties as well, so beware of this. Hope anyone finds this useful.

Johnny Egeland