ASP.Net发送电子邮件

  1. using System.Net;
  2. using System.Net.Mail;
  3. using System.Text.RegularExpressions;
  4. string toEmail, Subject, mailBody, fromEmail, SendSmtp;
  5.         fromEmail = "xiuxiu557711@163.com"//发件人邮箱
  6.         SendSmtp = "smtp.163.com"//smtp  
  7.         Subject = this.txttitle.Text.Trim().ToString();//邮件主题
  8.         mailBody = this.txtcontents.Text.Trim().ToString();//邮件内容
  9.         try
  10.         {
  11.             MailMessage mail = new MailMessage();
  12.             mail.From = new MailAddress(fromEmail);
  13.             mail.Subject = Subject;
  14.             mail.IsBodyHtml = true;
  15.             toEmail = this.TextBox2.Text;
  16.             mail.To.Add(toEmail);
  17.             mail.Body = mailBody;
  18.             SmtpClient client = new SmtpClient();
  19.             client.Host = SendSmtp;
  20.             client.Port = 25; //int.Parse(PortText);
  21.             client.Credentials = new NetworkCredential("zhou520909@163.com""******");//邮箱  密码
  22.             client.Send(mail);
  23.             Response.Write("scriptalert( /" 发送成功!/")script");        
  24.         }
  25.         catch (Exception ex)
  26.         {
  27.             //抛出异常
  28.             //throw new Exception(ex.Message, ex);
  29.             Response.Write("scriptalert(/"邮件发送出错!/")/script" + ex.Message.ToString());
  30.         }
最新回复(0)
/jishuHkbuqGwi7CL7Ll7OfnPGzsgUrugfCJNx2xXb1g_3D_3D4858164
8 简首页