发送邮件类

      先引用命名空间:using System.Net.Mail; 
    下面这这个邮件类直接用到项目中OK!!!
/// <summary> /// 发送邮件 /// </summary> /// <param name="to">接收方邮件地址</param> /// <param name="title">邮件标题</param> /// <param name="content">邮件正文内容</param> /// <returns></returns> /// <author>jeffrey zhang</author> /// <date>2012-4-16</date> static bool sendMail(string to, string title, string content) { string strHost = "xxx.163.com"; //STMP服务器地址 string strAccount = "xxx"; //SMTP服务帐号 string strPwd = "xxxx"; //SMTP服务密码 string strFrom = "xxxx@163.com"; //发送方邮件地址 SmtpClient _smtpClient = new SmtpClient(); _smtpClient.DeliveryMethod = SmtpDeliveryMethod.Network;//指定电子邮件发送方式 _smtpClient.Host = strHost; ;//指定SMTP服务器 _smtpClient.Credentials = new System.Net.NetworkCredential(strAccount, strPwd);//用户名和密码 MailMessage _mailMessage = new MailMessage(strFrom, to); _mailMessage.Subject = title;//主题 _mailMessage.Body = content;//内容 _mailMessage.BodyEncoding = System.Text.Encoding.UTF8;//正文编码 _mailMessage.IsBodyHtml = true;//设置为HTML格式 _mailMessage.Priority = MailPriority.High;//优先级 try { _smtpClient.Send(_mailMessage); return true; } catch { return false; } }
posted @ 2012-04-16 14:20  魔力鸟  阅读(305)  评论(0编辑  收藏  举报