Utilizing the MAILSPLF command to send a single report to multiple email addresses from a CL program
From Support
Enclosed is a sample CL program which can be used to call the MAILSPLF command from a CL program and pass up to 10 email addresses to the command call. We are using a technique where the MAILSPLF command line gets built dynamically in the program because the AS/400 command prompter won't let us simply pass all email addresses as one long variable, but we can build the command line programatically and then it works fine.
PGM
/* Define Email Address Fields as 50 Byte Char Fields */
DCL VAR(&TO1) TYPE(*CHAR) LEN(50)
DCL VAR(&TO2) TYPE(*CHAR) LEN(50)
DCL VAR(&TO3) TYPE(*CHAR) LEN(50)
DCL VAR(&TO4) TYPE(*CHAR) LEN(50)
DCL VAR(&TO5) TYPE(*CHAR) LEN(50)
DCL VAR(&TO6) TYPE(*CHAR) LEN(50)
DCL VAR(&TO7) TYPE(*CHAR) LEN(50)
DCL VAR(&TO8) TYPE(*CHAR) LEN(50)
DCL VAR(&TO9) TYPE(*CHAR) LEN(50)
DCL VAR(&TO10) TYPE(*CHAR) LEN(50)
/* Define CL command line up to 2000 chars */
DCL VAR(&CLCMD) TYPE(*CHAR) LEN(2000)
/* Set each TO address field you will be using. Here we use 2 email addresses */
CHGVAR VAR(&TO1) VALUE(RICHARD@RJSSOFT.COM)
CHGVAR VAR(&TO2) VALUE(RICHARD@RJSSOFT.COM)
/* Build a CL command line variable that contains all 10 email addresses */
/* This is done since the AS/400 command processor will not accurately */
/* allow us to pass all email addresses in a single variable field */
CHGVAR VAR(&CLCMD) VALUE('MAILSPLF FILE(RPTSAMPLE) +
SPLNBR(*LAST) TOADDRESS(' |< &TO1 |> &TO2 +
|> &TO3 |> &TO4 |> &TO5 |> &TO6 |> &TO7 +
|> &TO8 |> &TO9 |> &TO10 |< ')')
/* Run the MAILSPLF command line via QCMDEXC which is used to execute commands */
CALL PGM(QCMDEXC) PARM(&CLCMD 2000)
/* If errors occur during MAILSPLF, send escape message and bail out */
MONMSG MSGID(CPF0000) EXEC(SNDPGMMSG MSGID(CPF9898) +
MSGF(QCPFMSG) MSGDTA('Errors occurred +
while calling MAILSPLF') MSGTYPE(*ESCAPE))
RETURN /* Normal Exit */
ENDPGM
