日期:2014-05-18  浏览次数:21627 次

C#发送邮件乱码的问题
代码
C# code

string myMailEncoding = "BIG5";
            string myFromEmail = "ifitch@sina.com";
            string myFromName = "狗走猫步";

            string myToEmail = "ifitch@sina.com";
            string myToName = "扯把子打灰机";

            MailAddress from = new MailAddress(myFromEmail, myFromName, Encoding.GetEncoding(myMailEncoding));
            MailAddress to = new MailAddress(myToEmail, myToName, Encoding.GetEncoding(myMailEncoding));

            MailMessage myMessage = new MailMessage(from, to);

            myMessage.Subject = "狗走猫步-扯把子打灰机";
            myMessage.SubjectEncoding = Encoding.GetEncoding(myMailEncoding);

            myMessage.Body = "<h1>1v5这是邮件内容</h1>";
            myMessage.BodyEncoding = Encoding.GetEncoding(myMailEncoding);

            myMessage.IsBodyHtml = true;

            myMessage.Priority = MailPriority.High;

            SmtpClient smtp = new SmtpClient("smtp.sina.com");
            smtp.UseDefaultCredentials = false;
            smtp.Credentials=new NetworkCredential(myFromEmail, "密码");


            try
            {
                smtp.Send(myMessage);
                Response.Write("寄信成功");
            }
            catch
            {
                Response.Write("寄信失败");
            }



发送成功后,文字显示不正常


这个该如何解决呢?

------解决方案--------------------
又遇到了。老答案:试试UTF8或者GB2312编码
------解决方案--------------------
转换一下编码格式 试试吧