我在 IIS 中使用 httperrors 设置了一个自定义错误页面。
我需要发送一封电子邮件,简单地详细说明包含错误的页面。
我怎样才能做到这一点?最简单的方法是什么?
谢谢
我在 IIS 中使用 httperrors 设置了一个自定义错误页面。
我需要发送一封电子邮件,简单地详细说明包含错误的页面。
我怎样才能做到这一点?最简单的方法是什么?
谢谢
如果使用 ASP Classic,这里有一个错误处理子例程,其中包括一个电子邮件工具(使用 CDO.Message)。我建议您将错误记录到文件或最好是数据库中,尤其是当您发现收到大量无法管理的电子邮件时。此外,您可以比电子邮件更高效地查询日志文件或数据库。
sub geterror
' gather details about the error from the ASPError object
'Dim objasperror, code, num, src, cat
'Dim line, column, desc, adesc, file
' get the last error that occurred!
set objasperror = server.getlasterror
' go through the properties and get whatever you need...
With objasperror
code = .aspcode
num = .number
src = .source
cat = .category
file = .file
line = .line
column = .column
desc = .description
adesc = .aspdescription
end With
' free ASPError object
set objasperror = nothing
' write the error code
if code <> "" then errorMSG = (code & vbcrlf)
' using hex on the number property gives it
' that incomprehensible feel that has always
' been associated with ASP Error numbers...
if num <> "" then errorMSG = errorMsg & ("0x" & hex(num) & vbcrlf)
' source is the line of source code that made the error
if src <> "" then errorMSG = errorMsg & (src & vbcrlf)
' tells you what threw the error - could be IIS, VBScript or whatever...
if cat <> "" then errorMSG = errorMsg & (cat & vbcrlf)
' file is the actual page that crapped out on your site...
if file <> "" then errorMSG = errorMsg & (file & vbcrlf)
' line is the line that failed.
if line <> "" then errorMSG = errorMsg & (line & vbcrlf)
if line <> "" then errorLine = errorLine & (line)
' column is the character that failed
if column <> "" then errorMSG = errorMsg & (column & vbcrlf)
' returns a description of why the code failed, for
' example: variable not defined 'i'
if desc <> "" then errorMSG = errorMsg & (desc & vbcrlf)
if desc <> "" THEN errorDesc = errorDesc & (desc)
' if the error is an asp error, this property has more info for ya.
if adesc <> "" then errorMSG = errorMsg & (adesc & vbcrlf)
if errorMsg = "" THEN
errorMsg = "not available"
END IF
IF errorDesc = "" THEN
errorDesc = "not available"
END IF
for each x in Request.ServerVariables
errorSV = errorSV & Request.ServerVariables.Key(x) & "=" & Request.ServerVariables.Item(x) & vbcrlf
next
'format the above into a readable/helpful email body.
'also include server variables
emailbody = errorMSG & errorDesc & errorSV
'send an email with the details of the error message
Set myMail=CreateObject("CDO.Message")
myMail.From = emailfrom
myMail.Subject = emailsubject
myMail.To = emailrecipient
myMail.BodyPart.ContentTransferEncoding = "quoted-printable"
myMail.HTMLBody = emailbody
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing")=2
'Name or IP of remote SMTP server
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver")=smtpmailserver
'Server port
myMail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport")=25
myMail.Configuration.Fields.Update
myMail.Send
set myMail=nothing
End Sub
geterror 'calls the error subroutine