Asp.net C#具有特殊字符的电子邮件地址

时间:2021-07-08 01:41:26

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

我正在使用集成的System.Net.Mail发送电子邮件

i do like

我真的很喜欢

MailAddress abs = new System.Net.Mail.MailAddress("my@email.com", "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 个解决方案

#1


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.

它也可能是邮件服务器问题。尝试将其发送到各种电子邮件地址; POP3,WebMail等

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

这里有更多信息,虽然你可能已经看过这里:

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

#2


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.

我花了5个小时来调试类似的问题,我找到的解决方案也可能是这个问题的解决方案。由于没有人发布任何其他解决方案,我将贡献我的发现。

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.

.NET2.0 Mail API中似乎存在一个微妙的错误,导致邮件头中的收件人名称编码失败。如果在发送邮件之前访问MailMessage实例的To属性(可能还有其他),则会发生这种情况。

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

以下示例将导致To标头在没有编码的情况下发送,导致至少我的邮件客户端将名称显示为“?????? ...”:

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("address@example.com", "ÆØÅ 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:

但是,将WriteLine移动到发送行下方会导致To标头被正确编码:

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("address@example.com", "ÆØÅ 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.

我认为这个bug也会出现在Cc和Bcc属性上,所以要小心这一点。希望有人觉得这很有用。

#1


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.

它也可能是邮件服务器问题。尝试将其发送到各种电子邮件地址; POP3,WebMail等

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

这里有更多信息,虽然你可能已经看过这里:

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

#2


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.

我花了5个小时来调试类似的问题,我找到的解决方案也可能是这个问题的解决方案。由于没有人发布任何其他解决方案,我将贡献我的发现。

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.

.NET2.0 Mail API中似乎存在一个微妙的错误,导致邮件头中的收件人名称编码失败。如果在发送邮件之前访问MailMessage实例的To属性(可能还有其他),则会发生这种情况。

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

以下示例将导致To标头在没有编码的情况下发送,导致至少我的邮件客户端将名称显示为“?????? ...”:

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("address@example.com", "ÆØÅ 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:

但是,将WriteLine移动到发送行下方会导致To标头被正确编码:

MailMessage message = new MailMessage();
message.To.Add(new MailAddress("address@example.com", "ÆØÅ 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.

我认为这个bug也会出现在Cc和Bcc属性上,所以要小心这一点。希望有人觉得这很有用。