queue-message.pl
. queue-message.pl
will accept an incoming email message from the mailer and insert its contents into a queue
table in the database. A procedure can be scheduled to sweep the queue at
some interval to process the messages.
queue-message.pl
script
usage: queue_message.pl db_datasrc db_user db_passwd destaddr Inserts the data from stdin into a queue table. Assumes the following table and sequence are defined in the db: create table incoming_email_queue ( id integer primary key, destaddr varchar(256), content clob, -- the entire raw message content -- including all headers arrival_time date ); create sequence incoming_email_queue_sequence;The
destaddr
field is a string tag which you can assign
to a message, so that the routine which sweeps the queue can distinguish where
it came from. You might use this if you had several different mail recipient aliases
on your system, which all accept messages and put the into the queue.
To configure your mailer, you must add a mailer alias which invokes
the script. For sendmail, this would be done in the aliases file. For qmail,
you create a file in the qmail/alias
directory with a name
.qmail-your-alias-here
.
Example: You are setting up an email handler for user feedback messages.
.qmail-ticket-handler: |/web/yourwebserver/bin/queue-message.pl dbi:Oracle: yourdbuser yourdbpassword user_feedbackThe alias above specified that incoming messages will be piped to the perl script, which will connect to the specified database, and will insert the message with the tag "user_feedback".
Some guidelines: Try to sure that the from and reply-to headers on your outgoing message are not the same as your incoming mail handler alias. This will help prevent the possibility of nasty mailer loops, in the case where messages may bounce or be returned for some reason.
incoming_email_queue
Oracle table. So
the file /tcl/email-queue.tcl
schedules
the Tcl procedure process_email_queue
to sweep the queue, and will dispatch on each message tag to a procedure
which you specify in the email-handler section of ad.ini.
The example above specifies that tickets with the tag "na-support" will be passed to the procedure[ns/server/photonet/acs/email-queue] QueueSweepInterval=300 ; what to do with a new message ; format is tag|tcl_proc_to_invoke DispatchPair=na-support|ticket_process_message
ticket_process_message
.
The Tcl procedure invoked by the dispatcher is passed two arguments:
a database connection,
and the raw message text. It is up to you to parse or handle the message
in any way you wish. After the call to your dispatch procedure, the message is
deleted from the queue.
/tcl/email-utils.tcl
will help you
parse the raw mail message contents in the db.
parse_email_message message_body