当前位置: 代码迷 >> ASP.NET >> 利用cdo.sys发邮件中文标题乱码的有关问题?
  详细解决方案

利用cdo.sys发邮件中文标题乱码的有关问题?

热度:8372   发布时间:2013-02-25 00:00:00.0
利用cdo.sys发邮件中文标题乱码的问题??
本人使用以下方法发送邮件,在中文版的系统下没有问题,但是移植到英文版的系统就会出现中文乱码的问题,也知道是编码的问题,但不知道该怎么修改,请高手指点一下
VB.NET code
Imports CDOPublic Class sendEmail    Public Function send(ByVal toEmail, ByVal subject, ByVal content, ByVal htmlEnable) As Boolean        Dim msg As CDO.Message = New CDO.Message        Dim config As CDO.IConfiguration = msg.Configuration        Dim oFields As ADODB.Fields = config.Fields        Try            msg.From = "admin@test.com (管理员)"            msg.To = toEmail            msg.Subject = subject            If htmlEnable = 1 Then                msg.HTMLBody = content & "<br><a href='http://database/index.htm'>点击进行登录</a>"                msg.HTMLBodyPart.Charset = "gb2312"            Else                msg.TextBody = content                msg.BodyPart.Charset = "gb2312"            End If            oFields("http://schemas.microsoft.com/cdo/configuration/sendusing").Value = 2            oFields("http://schemas.microsoft.com/cdo/configuration/sendusername").Value = "admin"            oFields("http://schemas.microsoft.com/cdo/configuration/sendpassword").Value = "1234"            oFields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate").Value = 1            oFields("http://schemas.microsoft.com/cdo/configuration/smtpserver").Value = "test"            oFields("http://schemas.microsoft.com/cdo/configuration/languagecode").Value = "0x0804"            oFields.Update()            msg.Send()            Return True        Catch ex As Exception            Dim test As String = ex.Message.ToString()            Return False        Finally            msg = Nothing            oFields = Nothing        End Try    End Function


------解决方案--------------------------------------------------------
我是用jmail发送的。要是你不嫌麻烦,就改用jmail试试,也许就可以了呢

利用asp.net+Jmail发送Email
------解决方案--------------------------------------------------------
我的发送邮件的代码:

C# code
        public static void SendMail(string[] mailaddresses,string title,string body)        {            System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();            mail.Subject = title;            mail.From = new MailAddress("webmaster@xxx.com.cn");            foreach (string address in mailaddresses)            {                mail.To.Add(address);            }            mail.IsBodyHtml = true;            mail.Body = body;            mail.BodyEncoding = System.Text.Encoding.GetEncoding("gb2312");            mail.SubjectEncoding = System.Text.Encoding.GetEncoding("gb2312");            mail.Priority = MailPriority.High;            Send(mail);        }        private static void Send(System.Net.Mail.MailMessage mail)        {            SmtpClient sc = new SmtpClient();            sc.Credentials = new NetworkCredential(Config.GetConfigValue("SmtpUserName"), Config.GetConfigValue("SmtpUserPass"));            sc.Host = Config.GetConfigValue("SmtpAddress");            try            {                sc.Send(mail);            }            catch            {                ;            }        }
------解决方案--------------------------------------------------------
msg.From和msg.Subject是不同的吧,From去掉管理员和括号,在Subject里加中文试试呢
------解决方案--------------------------------------------------------
小灰(www.svnhost.cn),可以看看http://topic.csdn.net/u/20080327/14/753ef8e2-ed87-4d8d-a6ab-41ba9b8f49f5 
  相关解决方案