使用class mailmessage 的简单例子.

<%@ Import Namespace="System.Web.Mail" %>

<html>
 

  <script language="C#" runat="server">

    void Error_500(Object sender, EventArgs e) {
        String foo = null;
        Response.Write(foo.ToString());
    }

    void Page_Error(Object sender, EventArgs e) {

        String message = "<font face=verdana color=red>"
                               + "<h4>" + Request.Url.ToString() + "</h4>"
                               + "<pre><font color='red'>" + Server.GetLastError().ToString() + "</pre>"
                               + "</font>";

        Response.Write(message);
        Response.Write("此服务器上发生了错误,已通知该站点的管理员。");

        MailMessage mail = new MailMessage();
        mail.From = "[email protected]";
        mail.To = "[email protected]";
        mail.Subject = "站点错误";
        mail.Body = message;
        mail.BodyFormat = MailFormat.Html;
        SmtpMail.Send(mail);

        Server.ClearError();
    }

  </script>

  <body>
    <form runat="server">
      <h4><font face="宋体">导致发生错误...</font></h4>
      <asp:button text="500 服务器错误" OnClick="Error_500"  width="150" runat="server"/><p>
    </form>
  </body>

</html>

你可能感兴趣的:(html,C++,c,Web,asp)