Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail me error when occurs in asp page

Status
Not open for further replies.

avivit

Technical User
Jul 5, 2000
456
IL
I'd like to be e-mailed with any error happens in my asp pages. I am not the admin. So I have no direct access to the server.
Can I do it with code?
At least I'd like to make an if condition in certain asp pages:
if (certain) condition=true then
mail me a certain msg (that is made in advance if neccesary)

For e.g. I'd like to be alerted if in any serach a user made, there recordCount was bigger than 200, etc.

Anyone?
Thanks in advance
 
If you really want to get a mail when there is an error you could use the CDONTS mail method. Then set up a asp page that will run the email function. Then in your asp pages include that page and make an if statement that says something like this

if err.Number > 0 then
error_sub
end if

you will also want to put the on error resume next in there so the page keeps going after finding an error. Let me know if you need more info.

Roj
 
Yep...

The best way would be to include

"On Error Resume Next" at the top of your page, and then reference somewhere down the ASP script:

If Error.Count > 0 Then
...SYNTAX FOR CDO MESSAGE HERE...
Error.Clear
End If
 
I do need more info. :)
"...SYNTAX FOR CDO MESSAGE HERE..."
is the only thing I don't know how to handle and is the subject of my question. And it is skipped in the replies. The only part I need. :)
I see u mention CDO thing and CDONTS . Which I have no idea what it is.
I will check Mighty's links.
In the mean time, any more verbal explanation about the CDO is most welcome.
Thanks very much all. Pls keep keeping me posted. :)
 
Sure. CDO (or CDONTS...same thing) is a component which ships with Windows NT/2000 as part of IIS as a Web server application that lets you send e-mail from a Web page, triggered by an event, in this case the presence of an error.

Provided you have the SMTP service running on your server, and have ASP enabled, you should be able to incorporate CDO/CDONTS into your Web projects.

For your needs, I would recommend "trapping" the error within a statement....using the "On Error Resume Next" at the top of your page tells the browser to keep processing the remainder of your ASP script if it does detect an error, so it won't bomb out the entire page. Down further, you can use

If Error.Count > 0 Then
...SYNTAX FOR CDO MESSAGE HERE...
Error.Clear
End If

Wherein &quot;...SYNTAX FOR CDO MESSAGE HERE...&quot; contains a generic message is like so (<%
'Dimension variables
Dim objCDOMail 'Holds the CDONTS NewMail Object
'Create the e-mail server object
Set objCDOMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
'Who the e-mail is from
objCDOMail.From = &quot;myE-mailHere@myDomain.com&quot;
'Who the e-mail is sent to
objCDOMail.To = &quot;thereEmail@thereDomain.com&quot;
'Who the carbon copies are sent to
objCDOMail.Cc = &quot;myFriend1@thereDomain.com;myFriend2@anotherDomain.com&quot;
'Set the subject of the e-mail
objCDOMail.Subject = &quot;Enquiry sent from my web site&quot;
'Set the e-mail body format (0=HTML 1=Text)
objCDOMail.BodyFormat = 0
'Set the main body of the e-mail
objCDOMail.Body = &quot;<h2>Hello</h2><br><b>This is my e-mail in HTML format</b>&quot;
'Importance of the e-mail (0=Low, 1=Normal, 2=High)
objCDOMail.Importance = 1
'Send the e-mail
objCDOMail.Send
'Close the server object
Set objCDOMail = Nothing
%>

This way, when ever the page generates an error of any type, Error.Count will be greater than &quot;0&quot;, and fire the CDO script to send an e-mail. You could have this sent to yourself to alert yourself that something went wrong.

You can check:
For a very simple example on error handling with VBScript.
 
Ok. Thanks to you all. I also used Mighty's great links,
and discovers that......
We don't have it?
I got the error:
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
..Invalid class string

How should the admin install it?
By: Start / Control Panel / Add/Remove Programs / NT Option Pack 4, and see if the SMTP
(That's from Mighty's 1st link)?
Is there a specific thing that should be installed? Or all?
(i don't know how it should look like, I don't have the server here. :) )

Btw - My db is read only. It should not interfere with the mailing stuff, right?
Thanks
 
If you install the NT4 OPtion Pack, it automatically gets installed. You need to make sure that you have the CDONTS.dll file on your server. Mise Le Meas,

Mighty :)
 
Yep...that's about the same error you get if you try and run CDO/CDONTS applications on Personal Web Server (Win9x/ME) does not support CDO/CDONTS.

You've pretty much got it for the server install. SMTP should just need to be enabled, but ASP is a DLL file...appropriately, &quot;asp.dll&quot;.

IMPORTANT (I just learned this myself):
Microsoft has decided to remove the component from IIS 5.1 on Windows XP, so you will have to track down a copy of the cdonts.dll and register it on the IIS web server.

And your CDO mail should not interfere with DB records...as long as you don't include any DB fields in your CDONTS message. For your purpose, I don't think you will..if it's going to be used to report errors to you. You might also want to look into error trapping/error handling...so that any errors occuring on a page are shown to your users ina more friendlier manner than:
Server object error 'ASP 0177 : 800401f3'
Server.CreateObject Failed
..Invalid class string

With scripting, you can control this. :)

 
And if it's WIN-NT but NOT option pack 4, does he only have to download this CDONTS.dll file (from Microsoft site I guess), and enable the SMTP (which exist in any version of NT I suppose)?

Thanks for your help and detailed replies.
U r very very helpfull and patients.
 
No problem!

cdonts.dll should already be on the NT filesystem (I think), but it just may not be enabled. To do this, you make sure that the SMTP service is (1) installed and (2) running.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top