.net发送邮件

public bool SendMail(string to, string from, string title, string content, string userName, string password, string smtpHost)   
{     
    try  
    {
          MailAddress mail_from = new MailAddress(from);           
      MailAddress mail_to = new MailAddress(to);           
             MailMessage message = new MailMessage(mail_from, mail_to);           
      message.Subject = title;           
             message.IsBodyHtml = true;           
             message.Body = content;           
            SmtpClient client = new SmtpClient(smtpHost);           
            client.Credentials = new System.Net.NetworkCredential(userName, password);           
            client.DeliveryMethod = SmtpDeliveryMethod.Network;           
            client.Send(message);           
            return true;       
       }       
       catch (Exception ex)       
       {           
         Response.Write("<script>alert('" + ex.Message + "')</script>");           
     return false;       
       } 
}
posted @ 2011-06-02 17:45  oY_211  阅读(134)  评论(0编辑  收藏  举报