Frequently
Asked
Questions


Poll

Which Web server are you using with Active FoxPro Pages?
 


Navigation

Active FoxPro Pages FAQ
AFP 2.x
AFP in general
First steps
News
Plugins
Resources
Samples
Votes
Web server
FAQuarium
Glossary
Plugins
Server
Sidebar
Site Navigation Bar
Top Articles


Your Location

Germany


Partner Sites

- Microsoft Community Guide -
- AFPBB Boost your Board -
- AFP-Community -
- MiDeK - Internet Publishing -
- VfpNetwork.Com -
- MSDN VFP -
- CoDe Magazine -
- Golo Haas -


Advertisement

Imprint

Microsoft CLIP member

 
  [66] Drop a mail in case of an error
Rate this page Print Office Email Discuss
2244 requests - last updated Mittwoch, 06.10.2004

Based on article How to send e-mails with Active FoxPro Pages I would like to show how to use mail functionality to drop a message in case of an error in your Web application.

Notes:
If you're not familiar with AFP and mail, please read the introduction. Thanks.

Okay, what do we need:

  • AFP Engine - checked
  • Mail component - checked
  • AFP application - checked
  • Event_Error - wow, that's new...

That's our 'malefactor' - AFP event called Event_Error. This event is called due to an occuring error message while executing an AFP document. Normally the event is empty or not used cause standard behaviour of AFP should run.

And that's the best place to code a small hook to write our own error handler...
Okay, not really a new error handler but we are extending the existing one to automagically drop a mail:

Procedure Event_Error
	Local lcRecipient, lcSubject, lcBody
	Store "" To lcRecipient, lcSubject, lcBody

	*// Define error variables
	lcRecipient = "joki@afpfaq.de"
	lcSubject = "AFP FAQ - Fehlermeldung " + Transform(Datetime())
	lcBody = Error.ErrorHTML()

	* Send mail... :-)
	SendMail(m.lcRecipient, m.lcSubject, m.lcBody)
EndProc

Bingo!
That's all, really! Save your application, restart the AFP threads and enjoy. Next time an error occurs a mail will lose one's way in your mailbox.

But this is not the end of our journey... maybe
If you're already using the HTML-Plugin then use it here as well:

Procedure Event_Error
	Local lcRecipient, lcSubject, lcBody
	Store "" To lcRecipient, lcSubject, lcBody

	*// Define error variables
	lcRecipient = "joki@afpfaq.de"
	lcSubject = "AFP FAQ - Fehlermeldung " + Transform(Datetime())
	lcBody = Error.ErrorHTML()

	*// Strip any obsolete HTML elements
	lcBody = Html.InnerText(m.lcBody)

	*// Send mail... :-)
	SendMail(m.lcRecipient, m.lcSubject, m.lcBody)
EndProc

If you are not using the HTML plugin... Think about it ;-)
And now enjoy the definitively smaller text-based mails instead of those huge HTML-blown messages. Uhm, okay, only if the error message doesn't mean too much disaster.

In theory, it's possible to create an error mail / message for every single AFP document - even to abandon an AFP Web application is okay - but does it make sense?

Alternative configurations are left to your phantasies.

If have any questions or criticsm on this article, drop a mail at faq@afpfaq.de.

Enjoy the AFP FAQ, JoKi

All text is available under the terms of the
GNU Free Documentation License.

User contributed notesAdd a note
Copyright © 2002-2005 AFP FAQ. All rights reserved. Please send any irritations on this Web site to our Webmaster. Validate HTML