ASP实现404错误时自动发邮件管理员

实现的效果:
当访问出现404错误提示信息的时候系统会自动发一封邮件给管理员,这样就不必担心了也有不能访问的死链接了

把下面的带嵌入到404页面之后,设置好中间的帐号和密码。

代码如下:

<% @language="vbscript" %>
<% Option Explicit %>
<%
    Dim strPage, strReferer, strMessage
    Dim objSMTP
    ' Log the offending page
    strPage = Request.ServerVariables("HTTP_URL")
    ' Log the referer
    strReferer = Request.ServerVariables("HTTP_REFERER")
    ' Set up the email component
    Set objSMTP = Server.CreateObject("JMail.Message")
    objSMTP.From = "you@yourdomain.com"
    objSMTP.FromName = "Your Domain"
    objSMTP.Subject = "404 Error Logged"
    objSMTP.AddRecipient("you@yourdomain.com")
    ' Write the message
    strMessage = "Requested page: " & strPage & vbCrLf & vbCrLf
    If strReferer <> "" Then
        strMessage = strMessage & "Referer: " & strReferer
    Else
        strMessage = strMessage "The visitor typed the address in"
    End If
    objSMTP.Body = strMessage
    ' Send the message
    objSMTP.Send("mail.jzxue.com")
    ' Tidy up
    objSMTP.ClearRecipients
    objSMTP.Close()
    Set objSMTP = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
            "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
    <title>404 Page Not Found</title>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<h1>404 Page Not Found Error</h1>
<p>
Appropriate message here.
</p>
</body>
</html>

Related Posts