Have you heard of the QRYDST command?
Recently, someone asked me about using
the iSeries to re-process and report on "undeliverable" email. He was sending out a lot of email using the QtmmSendMail API and the SMTP server in OS/400
(i5/OS if you are keeping up). The problem was that email messages that were
returned as "undeliverable" were being ignored because the email messages were
being retrieved by one of the PC-based mail clients (Outlook, Eudora,
Thunderbird, etc.). The obvious answer is to retrieve the messages to the
iSeries and handle them from there.
The simplest way to accomplish this
is to use the QRYDST
and RCVDST
commands. Until my friend set me on a course to determine how to process email
on the AS/400 or iSeries, I was unfamiliar with the QRYDST command. Also, I had
only used the RCVDST command for receiving files that had been sent using SNDDST
(generally, *SAVF files or spooled files). Imagine my surprise when I found that
these two commands easily provide the foundation for a simple email
client.
The first order of business in retrieving email is to get the
list of the available email messages. The QRYDST command allows you to retrieve
all the incoming email either for a specific user ID or for any users that the
current user has been given authority to. For our purposes, we will stick to
retrieving email for a single user.
The IBM iSeries
Information Center offers some documentation about using SNADS to receive
email, but it's not clear on the format of the information that the QRYDST
command retrieves. You have to dig into the QRYDST command documentation to
discover that library QSYS contains two files, QAOSILIN and QAOSILOT. These
files are the templates for the output from the QRYDST and RCVDST commands. Once
you have this information, the IBM documentation for receiving emails using
QSNADS makes much more sense. The following command retrieves the list of email
messages for user ID JOLEN to a file called MAILLIST in library JEFFO.
Once the list of email messages is retrieved into a file using the QRYDST
command, you will use the distribution identifier (field LINDID from the
QAOSILIN template) and the RCVDST command to retrieve the specific email
messages. IBM has provided a template file in QSYS called QAOSIRCV that shows
the format of the RCVDST output file. The following command will retrieve a
specific email message identified by the distribution ID into the file
MAILMSGTMP in library JEFFO.
The IBM RCVDST documentation in the Information Center gives good
details on the contents of the email messages. From there, it's up to you, the
developer. Really, you could write a simple application to re-process and report
on any undeliverable email either from the email list from QRYDST or from the
actual message retrieved by RCVDST. Have fun!