Processing incoming mail

You can process Adaptive Server’s incoming e-mail queries manually by:

  1. Calling the ESPs xp_findnextmsg, xp_readmail, and xp_deletemail individually for each message

  2. Using xp_sendmail to execute the query in each message and send the e-mail results back to the requestor

However, it is much easier to use sp_processmail, which invokes these ESPs automatically.

sp_processmail reads and responds to the unread messages in the Adaptive Server inbox. You can determine which messages to process by passing a value for the originator parameter and/or the subject parameter, as shown in Table 9-2.

Table 9-2: Selecting messages by sender or subject

When you specify

sp_processmail processes

originator

Only mail from the specified sender

subject

Only mail with the specified subject header

originator and subject

Only mail by the specified sender with the specified subject header

Neither originator nor subject

The unread mail in the inbox

sp_processmail uses default parameters when invoking xp_sendmail, but you can override the dbname, dbuser, and separator defaults by passing these values to sp_processmail. For the syntax for sp_processmail and xp_sendmail, see the Adaptive Server Reference Manual.

The following example processes all the unread mail sent to Adaptive Server by the e-mail sender “admin”:

sp_processmail @originator = "admin",
@dbuser = "sa", @dbname = "db1"

The procedure executes the queries in the db1 database in the System Administrator’s context and returns the results an e-mail attachment to “admin” and to all the copied and blind-copied recipients of the original incoming message.