日期:2014-05-18 浏览次数:20554 次
Imports CDO Public 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
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.html
吗