Retrieve and Display a User’s E-mail Address in Control Language

Article ID: 56772

Most of us today use e-mail as one of our primary communication vehicles. The i/OS has built-in support for e-mail facilities that allow you to use the Post Office Protocol (POP) for an inbound e-mail server and/or the Simple Mail Transport Protocol (SMTP) for an outbound e-mail server. It’s quite nice to get an e-mail from a i/OS application program when an event occurs that you want to know about. You can also use e-mail as a means of report distribution.

i/OS e-mail does require some configuration steps. Thankfully, IBM has created and maintains a web page that contains e-mail information and links to everything there is to know about the topic.

With the above web page as a starting point it can be quite simple to get up and running on i/OS e-mail.

When a user is registered on the System i as an SMTP user, a directory entry is made using the WRKDIRE (Work with Directory Entries) command. Here, you can specify the user’s e-mail address. But once in the directory, there has been no easy way to get the e-mail address into a program...until now.

In this issue I present the commands DSPDIRSMTP(Display Directory Entry SMTP Name) and RTVDIRSMTP(Retrieve Directory Entry SMTP Name).

The RTVDIRSMTP command takes the following form:


                Retrieve Dir Entry SMTP Name (RTVDIRSMTP)
 Type choices, press Enter.

 User identifier:
   User ID  . . . . . . . . . . .   *USRPRF___    Character value, *USRPRF
   Address  . . . . . . . . . . .   ________      Character value
 User profile . . . . . . . . . .   *CURRENT__    Name, *CURRENT
 CL var for SMTPNAME     (63) . .   __________    Character value

This command must be used in a CL program and retrieves the E-Mail address of the user running the program, or the user specified on the command. The fully qualified e-mail address is returned into the CL variable named in the SMTPNAME parameter. The variable is defined as a character variable with a length of 63. See the command help text for a full discussion of the parameters.

The DSPDIRSMTP command takes the following form:


                   Display Dir Entry SMTP Name (DSPDIRSMTP)

Type choices, press Enter.

User identifier:
  User ID  . . . . . . . . . . .   *USRPRF___    Character value, *USRPRF
  Address  . . . . . . . . . . .   ________      Character value
User profile . . . . . . . . . .   *CURRENT__    Name, *CURRENT

This command will display the fully qualified e-mail address of the current user, or the user specified. Again, see the command help text for a full discussion of the parameters. When this command is run from a command line, a message is sent to the screen message line as shown here:

User profile CARSTEN SMTP name is Carsten.Flensburg@NOVASOL.DK

I have included a nice example program. This program is a message queue break-handling program that uses the RTVDIRSMTP command to retrieve the current user's SMTP address and forward the messages that arrive on the message queue to the user’s Email address.

The following source Code is included:

     CBX9411     RPGLE   Retrieve Directory Entry SMTP Address
     CBX9411H    PNLGRP  Retrieve Directory Entry SMTP Address
     CBX9411X    CMD     Retrieve Directory Entry SMTP Address

     CBX9412     CLP     Display Directory Entry SMTP Address
     CBX9412H    PNLGRP  Display Directory Entry SMTP Address
     CBX9412X    CMD     Display Directory Entry SMTP Address

     CBX9413     CLP     Break message handling program

See each source member for compile instructions.

Note: The RTVDIRSMTP command must exist before creating the objects for the DSPDIRSMTP command.

You can download a zip file containing all the source code here.

ProVIP Sponsors

ProVIP Sponsors