Processing Incoming Mail

You can manually process Adaptive Server incoming e-mail queries.

  1. Call the ESPs xp_findnextmsg, xp_readmail, and xp_deletemail individually for each message.
  2. Use xp_sendmail to execute the query in each message and send the e-mail results back to the requestor.
However, using sp_processmail invokes these ESPs automatically.

sp_processmail reads and responds to unread messages in the Adaptive Server inbox. You can determine which messages to process by passing a value for the originator parameter, the subject parameter or both.

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

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 Reference Manual: Procedures.

This 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.