Disclaimer: This is a sample command and program to show the use

Of SMTP e-mail. Reproduction of either the code or method is at

The users own risk. The SNDNETSPLF command is copyright IBM.

 

CMD PROMPT('Send Network Spool File')

PARM KWD(FILE) TYPE(*NAME) LEN(10) MIN(1) +

     PROMPT('Spool File Name')

             PARM       KWD(TOUSRID) TYPE(LIST1) MAX(1) +

                          PROMPT('SNADS User ID')

             PARM       KWD(TOEMUSR) TYPE(LIST2) MAX(1) +

                          PROMPT('E-Mail User ID')

             DEP        CTL(*ALWAYS) PARM((TOUSRID) (TOEMUSR)) +

                          NBRTRUE(*GE 1) MSGID(OFF0001)

             PARM       KWD(JOB) TYPE(JOBT) DFT(*) SNGVAL((* *)) +

                          PROMPT('Job name')

             PARM       KWD(SPLNBR) TYPE(*DEC) LEN(6 0) DFT(*ONLY) +

                          SPCVAL((*ONLY 0) (*LAST -1)) +

                          PROMPT('Spool file number') /* Spool File +

                          Number */

             PARM       KWD(SUBTXT) TYPE(*CHAR) LEN(44) DFT(*NONE) +

                          SPCVAL((*NONE)) PROMPT('E-Mail Subject')

             DEP        CTL(SUBTXT) PARM((TOEMUSR)) +

                          NBRTRUE(*GE 1) MSGID(OFF0002)

             PARM       KWD(PCFNAM) TYPE(*CHAR) LEN(12) DFT(*NONE) +

                          SPCVAL((*NONE)) PROMPT('Attachment File +

                          Name')

             DEP        CTL(PCFNAM) PARM((TOEMUSR)) +

                          NBRTRUE(*GE 1) MSGID(OFF0002)

             PARM       KWD(EMSTXT) TYPE(*CHAR) LEN(240) DFT(*NONE) +

                          SPCVAL((*NONE)) PROMPT('E-Mail Message')

             DEP        CTL(EMSTXT) PARM((TOEMUSR)) +

                          NBRTRUE(*GE 1) MSGID(OFF0002)

             PARM       KWD(DTAFMT) TYPE(*NAME) LEN(8) RSTD(*YES) +

                          DFT(*RCDDATA) SPCVAL((*RCDDATA) +

                          (*ALLDATA)) PROMPT('Data format')

             DEP        CTL(DTAFMT) PARM((TOUSRID)) +

                          NBRTRUE(*GE 1) MSGID(OFF0003)

 JOBT:       QUAL       TYPE(*NAME) LEN(10) MIN(1)

             QUAL       TYPE(*NAME) LEN(10) PROMPT('User')

             QUAL       TYPE(*CHAR) LEN(6) RANGE(000000 999999) +

                          PROMPT('Number')

 LIST1:      ELEM       TYPE(*CHAR) LEN(8) MIN(1) PROMPT('User ID')

             ELEM       TYPE(*CHAR) LEN(8) MIN(1) PROMPT('Address')

 LIST2:      ELEM       TYPE(*CHAR) LEN(30) MAX(1) PROMPT('E-Mail +

                          User ID')

             ELEM       TYPE(*CHAR) LEN(50) MAX(1) PROMPT('E-Mail +

                          Address (eg @xx.com)')

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

             PGM        PARM(&SPLFNM &TOUSRID &TOEMUSR &JOBDET +

                          &SPLFNO &SUBTXT &PCFNAM &EMSTXT &DTAFMT)

             DCL        VAR(&SPLFNM) TYPE(*CHAR) LEN(10)

             DCL        VAR(&TOUSRID) TYPE(*CHAR) LEN(18)

             DCL        VAR(&TOUSER) TYPE(*CHAR) LEN(30)

             DCL        VAR(&TOADDR) TYPE(*CHAR) LEN(50)

             DCL        VAR(&TO) TYPE(*CHAR) LEN(80)

             DCL        VAR(&TOEMUSR) TYPE(*CHAR) LEN(82)

             DCL        VAR(&JOBDET) TYPE(*CHAR) LEN(27)

             DCL        VAR(&JOBNM) TYPE(*CHAR) LEN(10)

             DCL        VAR(&USER) TYPE(*CHAR) LEN(10)

             DCL        VAR(&JOBNO) TYPE(*CHAR) LEN(6)

             DCL        VAR(&SPLFNO) TYPE(*DEC) LEN(6 0)

             DCL        VAR(&SUBTXT) TYPE(*CHAR) LEN(44)

             DCL        VAR(&PCFNAM) TYPE(*CHAR) LEN(12)

             DCL        VAR(&EMSTXT) TYPE(*CHAR) LEN(240)

             DCL        VAR(&DOCNAM) TYPE(*CHAR) LEN(8)

             DCL        VAR(&USERTXT) TYPE(*CHAR) LEN(50)

             DCL        VAR(&MSGID) TYPE(*CHAR) LEN(7)

             DCL        VAR(&MSGF) TYPE(*CHAR) LEN(10)

             DCL        VAR(&MSGFL) TYPE(*CHAR) LEN(10)

             DCL        VAR(&MSGDTA) TYPE(*CHAR) LEN(255)

             DCL        VAR(&DTAFMT) TYPE(*CHAR) LEN(8)

             DCL        VAR(&SNADUSR) TYPE(*CHAR) LEN(8)

             DCL        VAR(&SNADADR) TYPE(*CHAR) LEN(8)

             DCL        VAR(&USERCT) TYPE(*DEC) LEN(3 0)

             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(FAIL))

             DLTF       FILE(QTEMP/WPSPLF)

             MONMSG     MSGID(CPF0000)

             CHGVAR     VAR(&JOBNM) VALUE(%SST(&JOBDET 1 10))

             CHGVAR     VAR(&USER) VALUE(%SST(&JOBDET 11 10))

             CHGVAR     VAR(&JOBNO) VALUE(%SST(&JOBDET 21 6))

             IF         COND(&JOBNM = '*         ') THEN(DO)

             IF         COND(&SPLFNO = 0) THEN(DO)

             CHGSPLFA   FILE(&SPLFNM) JOB(*) SPLNBR(*ONLY)

             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NOSPLF))

             ENDDO

             ELSE   CMD(IF COND(&SPLFNO = -1) THEN(DO))

                    CHGSPLFA   FILE(&SPLFNM) JOB(*) SPLNBR(*LAST)

                    MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NOSPLF))

                    ENDDO

             ELSE       CMD(DO)

                    CHGSPLFA   FILE(&SPLFNM) JOB(*) SPLNBR(&SPLFNO)

                    MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NOSPLF))

             ENDDO

             ENDDO

             ELSE       CMD(DO)

             IF         COND(&SPLFNO = 0) THEN(DO)

             CHGSPLFA   FILE(&SPLFNM) JOB(&JOBNO/&USER/&JOBNM) +

                          SPLNBR(*ONLY)

             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NOSPLF))

             ENDDO

             ELSE       CMD(IF COND(&SPLFNO = -1) THEN(DO))

             CHGSPLFA   FILE(&SPLFNM) JOB(&JOBNO/&USER/&JOBNM) +

                          SPLNBR(*LAST)

             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NOSPLF))

             ENDDO

             ELSE       CMD(DO)

             CHGSPLFA   FILE(&SPLFNM) JOB(&JOBNO/&USER/&JOBNM) +

                          SPLNBR(&SPLFNO)

             MONMSG     MSGID(CPF0000) EXEC(GOTO CMDLBL(NOSPLF))

             ENDDO

             ENDDO

             CHGVAR     VAR(&USERCT) VALUE(%BINARY(&TOUSRID 1 2))

             IF         COND(&USERCT > 0) THEN(DO)

             CHGVAR     VAR(&SNADUSR) VALUE(%SST(&TOUSRID 3 8))

             CHGVAR     VAR(&SNADADR) VALUE(%SST(&TOUSRID 11 8))

             IF         COND(&JOBNM = '*         ') THEN(DO)

             IF         COND(&SPLFNO = 0) THEN(QSYS/SNDNETSPLF +

                          FILE(&SPLFNM) TOUSRID((&SNADUSR +

                          &SNADADR)) SPLNBR(*ONLY) DTAFMT(&DTAFMT))

             ELSE       CMD(IF COND(&SPLFNO = -1) +

                          THEN(QSYS/SNDNETSPLF FILE(&SPLFNM) +

                          TOUSRID((&SNADUSR &SNADADR)) +

                          SPLNBR(*LAST) DTAFMT(&DTAFMT)))

             ELSE       CMD(QSYS/SNDNETSPLF FILE(&SPLFNM) +

                          TOUSRID((&SNADUSR &SNADADR)) +

                          SPLNBR(&SPLFNO) DTAFMT(&DTAFMT))

             ENDDO

             ELSE       CMD(DO)

             IF         COND(&SPLFNO = 0) THEN(QSYS/SNDNETSPLF +

                          FILE(&SPLFNM) TOUSRID((&SNADUSR +

                          &SNADADR)) JOB(&JOBNO/&USER/&JOBNM) +

                          SPLNBR(*ONLY) DTAFMT(&DTAFMT))

             ELSE       CMD(IF COND(&SPLFNO = -1) +

                          THEN(QSYS/SNDNETSPLF FILE(&SPLFNM) +

                          TOUSRID((&SNADUSR &SNADADR)) +

                          JOB(&JOBNO/&USER/&JOBNM) SPLNBR(*LAST) +

                          DTAFMT(&DTAFMT)))

             ELSE       CMD(QSYS/SNDNETSPLF FILE(&SPLFNM) +

                          TOUSRID((&SNADUSR &SNADADR)) +

                          JOB(&JOBNO/&USER/&JOBNM) SPLNBR(&SPLFNO) +

                          DTAFMT(&DTAFMT))

             ENDDO

LOOP:

             RCVMSG     MSGQ(*PGMQ) MSGTYPE(*COMP) MSGDTA(&MSGDTA) +

                          MSGID(&MSGID) MSGF(&MSGF) MSGFLIB(&MSGFL)

             MONMSG     MSGID(CPF2415) EXEC(GOTO CMDLBL(ENDLOOP))

             IF         COND(&MSGID *NE 'CPC8053') THEN(GOTO +

                          CMDLBL(LOOP))

ENDLOOP:

             IF         COND(&MSGID *EQ 'CPC8053') THEN(SNDPGMMSG +

                          MSGID(CPC8053) MSGF(&MSGFL/&MSGF) +

                          MSGDTA(&MSGDTA))

             ELSE       CMD(GOTO CMDLBL(FAIL))

             ENDDO

             IF         COND(&TOEMUSR = '          ') THEN(RETURN)

             CHGVAR     VAR(&TOUSER) VALUE(%SST(&TOEMUSR 3 30))

             CHGVAR     VAR(&TOADDR) VALUE(%SST(&TOEMUSR 33 50))

             CHGVAR     VAR(&TO) VALUE(&TOUSER *TCAT &TOADDR)

             CRTPF      FILE(QTEMP/WPSPLF) RCDLEN(198)

             MONMSG     MSGID(CPF0000)

             IF         COND(&PCFNAM = '*NONE       ') THEN(DO)

             CHGVAR     VAR(&PCFNAM) VALUE(&SPLFNM *TCAT '.TXT')

             ENDDO

             IF         COND(&JOBNM = '*         ') THEN(DO)

             IF         COND(&SPLFNO = 0) THEN(CPYSPLF FILE(&SPLFNM) +

                          TOFILE(QTEMP/WPSPLF) JOB(*) SPLNBR(*ONLY) +

                          MBROPT(*ADD))

             ELSE       CMD(IF COND(&SPLFNO = -1) THEN(CPYSPLF +

                          FILE(&SPLFNM) TOFILE(QTEMP/WPSPLF) JOB(*) +

                          SPLNBR(*LAST) MBROPT(*ADD)))

             ELSE       CMD(CPYSPLF FILE(&SPLFNM) +

                          TOFILE(QTEMP/WPSPLF) JOB(*) +

                          SPLNBR(&SPLFNO) MBROPT(*ADD))

             ENDDO

             ELSE       CMD(DO)

             IF         COND(&SPLFNO = 0) THEN(CPYSPLF FILE(&SPLFNM) +

                          TOFILE(QTEMP/WPSPLF) +

                          JOB(&JOBNO/&USER/&JOBNM) SPLNBR(*ONLY) +

                          MBROPT(*ADD))

             ELSE       CMD(IF COND(&SPLFNO = -1) THEN(CPYSPLF +

                          FILE(&SPLFNM) TOFILE(QTEMP/WPSPLF) +

                          JOB(&JOBNO/&USER/&JOBNM) SPLNBR(*LAST) +

                          MBROPT(*ADD)))

             ELSE       CMD(CPYSPLF FILE(&SPLFNM) +

                          TOFILE(QTEMP/WPSPLF) +

                          JOB(&JOBNO/&USER/&JOBNM) SPLNBR(&SPLFNO) +

                          MBROPT(*ADD))

             ENDDO

             CPYTOPCD   FROMFILE(QTEMP/WPSPLF) TOFLR(EMAILOUT) +

                          TODOC(&PCFNAM) REPLACE(*YES)

             CHGDOCD    DOC(&PCFNAM) FLR(EMAILOUT) DOCD(&SUBTXT)

             SNDDST     TYPE(*DOC) TOUSRID((INTERNET SMTPRTE)) +

                          TOINTNET((&TO)) DSTD('AS/400 +

                          Spoolfile') MSG(&EMSTXT) USRID(*CURRENT) +

                          DOC(&PCFNAM) FLR(EMAILOUT)

             DLTDLO     DLO(&PCFNAM) FLR(EMAILOUT)

             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Email +

                          Message Created') MSGTYPE(*COMP)

             RETURN

NOSPLF:

             RCVMSG     MSGQ(*PGMQ) MSGTYPE(*EXCP) MSGDTA(&MSGDTA) +

                          MSGID(&MSGID) MSGF(&MSGF) MSGFLIB(&MSGFL)

             SNDPGMMSG  MSGID(&MSGID) MSGF(&MSGFL/&MSGF) +

                          MSGDTA(&MSGDTA)

             RETURN

FAIL:

             SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Unable +

                          to create Email message - see low level +

                          messages')

             ENDPGM

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Code Samples:

 

RPG:

 *

FJMPETX  O   F      70            DISK                      UC

 *

C                     MOVE WWDATA    WWETXT 69

C                     MOVE X'06'     WWECRT  1

 *

C                     EXCPTELINE

 *

OJMPETX  E                ELINE

O                         WWETXT    69

O                         WWECRT    70

 

 

 

CL:

PGM        PARM(&COMM &USER &DOMAIN)

             DCL        VAR(&COMM) TYPE(*CHAR) LEN(1)

             DCL        VAR(&USER) TYPE(*CHAR) LEN(20)

             DCL        VAR(&DOMAIN) TYPE(*CHAR) LEN(20)

             DCL        VAR(&FULLADD) TYPE(*CHAR) LEN(64)

             CHGVAR     VAR(&FULLADD) VALUE(&USER *TCAT &DOMAIN)

             SNDDST     TYPE(*FILE) TOUSRID((INTERNET SMTPRTE)) +

                          TOINTNET((&FULLADD)) DSTD('Prices +

                          Distribution') DOCFILE(JMPETX) +

                          DOCMBR(JMPETX) DOCTYPE(*FFT) DOCD('Latest +

                          Prices') +

                                    USRID(SALES AS400NAME) +

                          AUTHOR('Sales Desk')

             CLRPFM     FILE(JMPETX)

             ENDPGM