You need to notify someone when a batch job finishes. The shortest route is SNDSMTPEMM,
an ordinary CL command that requires nothing to be installed.
DCL VAR(&TIME) TYPE(*CHAR) LEN(6)
RTVSYSVAL SYSVAL(QTIME) VAR(&TIME)
SNDSMTPEMM RCP((operations@company.com)) +
SUBJECT('Month end close completed') +
NOTE('Processing finished at ' *CAT &TIME)
The time comes from RTVSYSVAL on QTIME, a six-character value in HHMMSS form.
To attach a file from the IFS, add ATTACH, with the path, the MIME type and the transfer
method: IBM's page says type and method must be given. *PLAIN and *TXT are those for a text
file; for a binary file IBM indicates *OCTET and *BIN.
SNDSMTPEMM RCP((operations@company.com)) +
SUBJECT('Close report') +
NOTE('Summary attached.') +
ATTACH(('/home/batch/close.csv' *PLAIN *TXT))
Example: the batch that reports how it went
Mail that arrives only when everything went well is worth nothing: nobody notices the mail that did not arrive. The useful one distinguishes the two outcomes.
PGM
DCL VAR(&TIME) TYPE(*CHAR) LEN(6)
CALL PGM(PRODLIB/CLOSE)
MONMSG MSGID(CPF0000) EXEC(DO)
RTVSYSVAL SYSVAL(QTIME) VAR(&TIME)
SNDSMTPEMM RCP((operations@company.com)) +
SUBJECT('MONTH END FAILED') +
NOTE('Stopped at ' *CAT &TIME *CAT +
'. Job log needs checking.')
RETURN
ENDDO
RTVSYSVAL SYSVAL(QTIME) VAR(&TIME)
SNDSMTPEMM RCP((operations@company.com)) +
SUBJECT('Month end completed') +
NOTE('Finished at ' *CAT &TIME)
ENDPGM
The RETURN inside the DO is what stops the success mail going out right behind the failure
one. Without it both arrive, and the second erases the first in the reader's head.
Worth putting the outcome in the subject rather than the body: people checking mail on a phone see only that.
Warning
the command fails without saying which prerequisite is missing, and there are
two. The SMTP server must be started: after STRTCPSVR SERVER(*SMTP), check the jobs
actually came up with WRKACTJOB SBS(QSYSWRK), looking for QTSMTPCLTD and QTSMTPSRVD.
The profile must be enrolled in the directory that CHGSMTPA sets with DIRTYPE: with
*SDD, an entry in the system distribution directory (WRKDIRE) and an SMTP name
(WRKNAMSMTP); with *SMTP or *SMTPMSF, ADDUSRSMTP.
Tip
when the mail leaves but never arrives, the prerequisites are not the problem. The
place to look is the forwarding mailhub, read with CHGSMTPA: without a valid forwarder the
system accepts the message and delivers it to nobody.
Note
NOTE takes up to 5000 characters. For longer messages, write the body to a
file on the IFS and attach it rather than composing it in the program.
Releases. SNDSMTPEMM is present on every release still in support. The real constraint
is not the version but the configuration: SMTP started and the profile present in the system
directory. Checked with WRKACTJOB SBS(QSYSWRK) and, depending on DIRTYPE, with WRKDIRE and
WRKNAMSMTP or with WRKSMTPUSR.
Comments
No comments yet. Be the first to comment!
You need an account to comment. Log in · Sign up