ASP.NET发送邮件

Posted on 2007-11-02 21:23  Flying to the top  阅读(156)  评论(0)    收藏  举报
string sReturn = string.Empty;
   MailMessage mailMsg = new MailMessage();
   mailMsg.BodyFormat = MailFormat.Html;
   mailMsg.To ="ph871129@126.com";
   mailMsg.From = "ph871129@126.com";
   mailMsg.Subject = "这是邮件的主题哦";
   mailMsg.Body = "这就是内容了哦";

   mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1");
   mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", "这里是发信人邮箱");
   mailMsg.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", "这里是密码");
   //
   SmtpMail.SmtpServer ="smtp.126.com";//smpt服务器
   try
   {

    SmtpMail.Send(mailMsg);
    this.Label1.Text = "发送成功";
   }
   catch (Exception err)
   {
    this.Label2.Text = "<font color=red>发送失败" + err.Message.ToString() + "</font>";
   }

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3