IBMi (AS400) fans only : How to send a spool file per Email as TXT attachment

This CLP sends a SpoolFile per Email as TXT attachment


#IBMiSample

This CLP sends a SpoolFile per Email as TXT attachment and need 4 parameters:
&SPOOLF Spool file name
&SUBJCT Subject
&BODY00 body
&MAIL01 Email

(Pay attention at the "Send Email" note at the bottom)

Compile this CLP source with:
CRTCLPGM PGM(myLib/SNDSPLF) SRCFILE(myLib/mySourceFile) SRCMBR(SNDSPLF)


SNDSPLF.CLP
 
 
 
             PGM        PARM(&SPOOLF &SUBJCT &BODY00 &MAIL01)
/*****************************************************************************/
/* Send a SpoolFile per Email as TXT attachment                              */
/* &SPOOLF Spool file name                                                   */
/* &SUBJCT Subject                                                           */
/* &BODY00 body                                                              */
/* &MAIL01 Email                                                             */
/* Try with:                                                                 */
/* CALL PGM(SNDSPLF) PARM(('MySpoolfileName') ('MySubject') ('MyBody') +     */
/*       ('MyEmailAddress'))                                                 */
/*****************************************************************************/
             DCL        VAR(&SPOOLF) TYPE(*CHAR)  LEN(10)
             DCL        VAR(&SUBJCT) TYPE(*CHAR) LEN(048)
             DCL        VAR(&BODY00) TYPE(*CHAR) LEN(048)
             DCL        VAR(&MAIL01) TYPE(*CHAR) LEN(020)

             DCL        VAR(&JOBNUM) TYPE(*CHAR) LEN(   6)
             DCL        VAR(&JOBUSR) TYPE(*CHAR) LEN(  10)
             DCL        VAR(&JOBNAM) TYPE(*CHAR) LEN(  10)
             DCL        VAR(&USER  ) TYPE(*CHAR) LEN(010)
             DCL        VAR(&SDIR  ) TYPE(*CHAR) LEN(100)
/*****************************************************************************/
/* START                                                                     */
/*****************************************************************************/
             RTVJOBA    JOB(&JOBNAM) USER(&JOBUSR) NBR(&JOBNUM)
             CHGVAR     VAR(&SUBJCT) VALUE(%TRIM(&SUBJCT))
             CHGVAR     VAR(&BODY00) VALUE(%TRIM(&BODY00))
             CHGVAR     VAR(&MAIL01) VALUE(%TRIM(&MAIL01))
/*--------------------------------------------------------------*/
/* if already exist, delete workfile SNDSPLTXT                  */
/*--------------------------------------------------------------*/
             DLTF       FILE(QTEMP/SNDSPLTXT)
             MONMSG     MSGID(CPF0000)
/*--------------------------------------------------------------*/
/* create workfile SNDSPLTXT 198 columns                        */
/*--------------------------------------------------------------*/
             CRTPF      FILE(QTEMP/SNDSPLTXT) RCDLEN(198)
/*--------------------------------------------------------------*/
/* Copy the spoolfile into workfile SNDSPLTXT                   */
/*--------------------------------------------------------------*/
             CPYSPLF    FILE(&SPOOLF) TOFILE(QTEMP/SNDSPLTXT) JOB(&JOBNUM/&JOBUSR/&JOBNAM) +
                          SPLNBR(*LAST)
/*--------------------------------------------------------------*/
/* build path &SDIR                                             */
/* Path looks like this:                                        */
/* /SNDSPLF/(username)                                          */
/* If not exist, the path will be created                       */
/*--------------------------------------------------------------*/
             CRTDIR     DIR('/SNDSPLF')
             MONMSG     MSGID(CPF0000)
             RTVUSRPRF  RTNUSRPRF(&USER)
             CHGVAR     VAR(&SDIR) VALUE('/SNDSPLF/' *CAT &USER)
             CRTDIR     DIR(&SDIR)
             MONMSG     MSGID(CPF0000)
             CHGVAR     VAR(&SDIR) VALUE('/SNDSPLF/' *CAT %TRIM(&USER) *CAT '/SNDSPLTXT.TXT')
             RMVLNK     OBJLNK(&SDIR)
             MONMSG     MSGID(CPF0000)
/*--------------------------------------------------------------*/
/* Copy spoolfile into IFS                                      */
/*--------------------------------------------------------------*/
             CPYSPLF    FILE(&SPOOLF) TOFILE(*TOSTMF) JOB(&JOBNUM/&JOBUSR/&JOBNAM) +
                          SPLNBR(*LAST) TOSTMF(&SDIR)
/*--------------------------------------------------------------*/
/* Send Email                                                   */
/*--------------------------------------------------------------*/
/* Sorry, I have no permission on PUB400 to use SNDSMTPEMM, but the following */
/* must be the righ sintax. Contact me if not.                                */
         /*  SNDSMTPEMM RCP((&MAIL01)) SUBJECT(&SUBJCT) NOTE(&BODY00) ATTACH((%TRIM(&SDIR) +
                          *PLAIN *TXT)) CONTENT(*HTML)    */
/*--------------------------------------------------------------*/
/* Clear IFS                                                    */
/*--------------------------------------------------------------*/
             RMVLNK     OBJLNK(&SDIR)
             MONMSG     MSGID(CPF0000)

             ENDPGM   


I appreciate all the comments made on this blog.

Comments

  1. I had hoped that your article would describe the prerequisite setup tu use the SNDSMTPEMM command...
    Command tells me '..successfull..' but mails ends up in a queue, from which they are tried sent with no messages or 'success'.
    What are the prereq parms setup for the SNDSMTPEMM command??

    ReplyDelete
    Replies

    1. the command is CHGSMTPA
      I hope this could help you to configure your smtp
      https://www.markonetools.it/configurazione-smtp/

      Delete

Post a Comment

Popular posts from this blog

(IBM i fans only) Efficient WRKSPLF with WSF - How to Search string into spooled files, Sort, and Generate PDFs on IBMi

(IBM i fans only) Detecting and Handling Non-Printable Characters in DB2 SQL Using LOCATE() and REPLACE() Functions

(IBM i fans only) How to Sniff User Access