简单自动邮件发送

   /// <summary>

        /// Send_mail类。

        /// </summary>

        /// <remarks>

        /// StrMail_other:发送给对方的Emai,strMail_subject: 发邮件的标题,strMail_selff : 自己的Emai,StrMail_Name:发出邮件的邮件名称, StrMail_selfpwd:自己邮箱的密码,StrEmail_Server:邮箱的服务器,要注意各个邮箱不同的服务器,sMailCont:邮箱的正式内容;

        /// </remarks>

protected void Send_mail(string StrMail_other, string strMail_subject, string strMail_self, string StrMail_Name, string StrMail_selfpwd, string StrEmail_Server,string sMailCont)

{

 System.Net.Mail.MailMessage MyEmail = new System.Net.Mail.MailMessage();

 MyEmail.To.Add(StrMail_other);

 MyEmail.From = new MailAddress(strMail_self, StrMail_Name,System.Text.Encoding.UTF8);

 MyEmail.Subject = strMail_subject;//邮件标题

 MyEmail.Body = sMailCont + "<br>";

 MyEmail.SubjectEncoding = System.Text.Encoding.UTF8;//邮件标题编码

 MyEmail.IsBodyHtml = true;//邮件形式,.Text、.Html  

 SmtpClient client = new SmtpClient();

 client.Credentials = new System.Net.NetworkCredential(strMail_self, StrMail_selfpwd);

 client.Host = StrEmail_Server; //邮箱服务器如:Mail.covics.com

 try

 {

    client.Send(MyEmail);

 }

 catch (System.Net.Mail.SmtpException ex)

        {

         return ;

         }

}

posted @ 2008-12-03 13:16  黄建成  阅读(315)  评论(0)    收藏  举报