ORA Mail Routine for Windows NT
Abstract
The routines contained in this distribution provides an easy method to generate and send email from any Oracle-based application (i.e., Oracle Forms, PL/SQL Packages & Procedures, or Database Triggers). It accomplishes this by storing email in a table and periodically "flushing" the contents into DOS-based scripts and text files, which are then sent through a SMTP host via a DOS command-line application. This distribution utilizes BLAT. See http://www.interlog.com/~tcharron/blat.html for more information and distribution. Please note that the BLAT utility is not included in this distribution.
Contents
Setup Sub-folder
Create_Mail_Blats.sql |
Creates two tables: one to store outgoing messages and one history table to store sent messages. Creates the sequence generator required to give each message a unique ID. Create a pre-insert trigger to set the sequence number, the "timestamp", and some necessary formatting. |
Format_Email.sql |
Creates a package that reformats the message by placing end-of-line characters at appropriate intervals to prevent long lines. Some email clients don’t handle long lines very well. |
DBMS_Office.sql |
Creates a package to replace the routine provided by Oracle’s Interoffice. It accepts the same parameters in the same order. When called, this package inserts the data into the tables described above. |
Note: The scripts in the "setup" sub-folder are executed only once.
Mail Folder (Ora_Mail)
ORA_Mail.bat |
This is the main routine. It generates DOS batch files (one for each message). Run this script at appropriate intervals. Note: Initially, I used the "soon" command found on the NT Resource Kit. Later versions of NT4 service packs include a "Scheduled Tasks" utility that works much better. |
Send_Mail.sql |
This script generates a temporary batch file (send_mail.bat). Send_Mail.bat contains calls to build_batch.bat passing it several parameters; including email addresses, subject, etc. |
Cre_Txt.sql |
This scripts generates text files containing the email message. The BLAT routine accepts a DOS file name that represents the body of the outgoing email message. |
Build_Batch.bat |
This routine creates individual batch files (one for each outgoing email message) using the naming convention of Mail_nnn.bat where nnn represents the sequence number of the email message stored in the mail_blats table. The last step in ORA_Mail.bat calls each batch filed created by Build_Batch, which send the email via BLAT. |
Resend_ID.sql |
This script copies a message from the history table and places it back in the outgoing email table. After all, nothing’s perfect and you may need to re-send a message if your SMTP server dies. |
Installation
1. Using SQL*Plus log into the schema to hold the email messages. Note: for Prism’s FAMIS customers choose the schema that owns the FMM tables.
2. Execute Create_Mail_Blats.sql (Note: You may wish to change the initial and next values on the create table statements based on anticipated email volume.)
3. Execute Format_Email.sql
3. Optional: Execute DBMS_Office.sql (this is required only if you have applications that utilize Oracle’s Interoffice). Prism’s FAMIS customers: this is not optional.
4. Place the contents of the Ora_Mail folder on any Windows NT system that has access to the database that contains the tables created in step 1. This can be the database server or a client with SQL*Net access.
5. Edit the file Build_Batch.bat and replace the strings ADMINISTRATOR@YOUR_DOMAIN with an appropriate email address.
6. Edit the file Ora_Mail.bat. Change the drive letter and/or the directory if necessary. Change the SQL Plus command line if necessary (e.g. use plus73 for Oracle 7.3 databases). Change the username and password to the schema name and password used in step 1.
7. Edit the file Send_Mail.sql Change the string DEFAULT_USER@YOUR.DOMAIN to an appropriate value. This is the default email address used as the "from address" if not specified in the database. In other words, email will arrive as if it were send by the from address. A from address is required by BLAT.
8. Execute the batch file Ora_Mail.bat. It is best to use the Windows NT "Scheduled Tasks" feature. It is easy to use and you can setup multiple schedules. For example, I schedule this task every 10 minutes during business hours and hourly on business nights. It runs every 2 hours over the weekend. I’m not sure when "Scheduled Tasks" became available. I’m running NT4 SP5 but I believe it was released on a previous service pack.