8.3. Receiving Email Inside the Database

In some applications, it's also important to be able to receive an email, process it in some fashion, and load some or all of its contents into the database. For example, a book publisher may send out a specially-formatted email message every week containing a schedule of their upcoming releases, and a library might want to load that information and make it available in their database.

8.3.1. What Are My Options?

While Oracle built-ins like UTL_TCP exist that could make it possible to receive email completely inside a stored procedure, I doubt that many of us would really want to go to that much trouble. Here is the general scenario I have in mind:

  1. Create a special email address on a convenient mail server.

  2. If the mail server isn't the same machine as the database server, use a program like GNU fetchmail that will pull the mail down to the local machine.

  3. Now that the mail data is available in a mail file on the local machine, use one of a variety of techniques to load the email data from the file into the database.

Techniques for loading data from a file into the Oracle database (step 3) include:

SQL*Loader

A command-line utility that uses a programmer-supplied "control file" describing the contents of the data file

External tables (as of Oracle9i)

A way to store this "control file" information in the database itself, enabling query of the data file in a manner similar to a regular table

UTL_FILE

A PL/SQL built-in package that ...

Get Learning Oracle PL/SQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.