2003-07-03 如何將報表(Spooled File) 使用 e-mail 傳輸至使用者 ?(工具:ESPLF)
由於 E-mail 的普及,所以常會有 AS/400 報表下載至 PC 並利用 outlook 傳輸,
甚為麻煩,所以我將之整合至 AS/400 中,直接利用 AS/400 的 SMTP 功能即可直
接傳送報表。SMTP設定方式請參考指令 ESPLF 的原始檔說明。
此程式預設是轉換 繁體中文 "*BG5",若是簡體中文,請將 ESPLFC 中 指令 CPYTOPCD 參數 TRNIGC 值改為 "*SCGS",即可轉換簡體。
File : QCLSRC
Member: ESPLFC
Type : CLP
Usage : CRTCLPGM ESPLFC
OS Version: V4R1(含)以後
/**================================================================**/
/* ESPLF ** EMAIL SPOOL FILE */
/* Compile: CRTCLPGM PGM(QGPL/ESPLFC) */
/**================================================================**/
PGM PARM(&FILE &EMAIL &QJOB &SPLNBRD)
DCL VAR(&QJOB) TYPE(*CHAR) LEN(26) /* job name */
DCL VAR(&FILE) TYPE(*CHAR) LEN(10) /* spool file +
name */
DCL VAR(&SPLNBRD) TYPE(*DEC) LEN(5 0) /* spool +
file number */
DCL VAR(&EMAIL) TYPE(*CHAR) LEN(40) /* to email +
address */
DCL VAR(&JOB) TYPE(*CHAR) LEN(10)
DCL VAR(&USER) TYPE(*CHAR) LEN(10)
DCL VAR(&NBR) TYPE(*CHAR) LEN(6)
DCL VAR(&SPLNBR) TYPE(*CHAR) LEN(6) /* spool +
file number */
DCL VAR(&FNAME) TYPE(*CHAR) LEN(12)
MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERROR))
/**================================================================**/
/* Translate JOB special values */
/**================================================================**/
IF COND(&QJOB = '*') THEN(RTVJOBA JOB(&JOB) +
USER(&USER) NBR(&NBR))
ELSE CMD(DO)
CHGVAR VAR(&JOB) VALUE(%SST(&QJOB 1 10))
CHGVAR VAR(&USER) VALUE(%SST(&QJOB 11 10))
CHGVAR VAR(&NBR) VALUE(%SST(&QJOB 21 6))
ENDDO
/**================================================================**/
/* Translate SPLNBR special values */
/**================================================================**/
IF COND(&SPLNBRD = -1) THEN(CHGVAR VAR(&SPLNBR) +
VALUE('*ONLY'))
ELSE CMD(IF COND(&SPLNBRD = -2) THEN(CHGVAR +
VAR(&SPLNBR) VALUE('*LAST')))
ELSE CMD(CHGVAR VAR(&SPLNBR) VALUE(&SPLNBRD))
/**================================================================**/
/* E-mail */
/**================================================================**/
CHKOBJ OBJ(QTEMP/ESPLF) OBJTYPE(*FILE)
MONMSG MSGID(CPF9801) EXEC(CRTPF FILE(QTEMP/ESPLF) +
RCDLEN(198) IGCDTA(*YES) SIZE(*NOMAX))
CPYSPLF FILE(&FILE) TOFILE(QTEMP/ESPLF) +
JOB(&NBR/&USER/&JOB) SPLNBR(&SPLNBR) +
MBROPT(*REPLACE)
CHGVAR VAR(&FNAME) VALUE(%SST(&FILE 1 8) *TCAT '.TXT')
CPYTOPCD FROMFILE(QTEMP/ESPLF) TOFLR('temp') +
TODOC(&FNAME) REPLACE(*YES) +
TRNTBL(*NONE) TRNIGC(*BG5)
SNDDST TYPE(*DOC) TOINTNET((&EMAIL)) DSTD(&FILE) +
LONGMSG(&FILE) DOC(&FNAME) FLR('temp') +
SUBJECT(&FILE *BCAT 'TESTED' )
DLTDLO DLO(&FNAME) FLR('temp')
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Spooled +
file' |> &FILE |> 'sent to' |> &EMAIL)
RETURN
/**================================================================**/
/* Global exception handler */
/**================================================================**/
ERROR: CALL PGM(QMHRSNEM) PARM(' ' X'00000000')
MONMSG MSGID(CPF0000)
SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) +
MSGDTA('Error(s) occured, see previously +
listed messages') MSGTYPE(*ESCAPE)
ENDPGM
File : QCMDSRC
Member: ESPLF
Type : CMD
Usage : CRTCMD CMD(ESPLFC) PGM(ESPLFC)
OS Version: V4R1(含)以後
/* sample: ESPLF FILE(QPJOBLOG) EMAIL(support@yahoo.com) */
/* V4R1 or later is required. */
/*You must create a temporary folder using the command CRTFLR FLR(TEMP) */
/* 1.Using CFGTCP, Option 10=Work with TCP/IP host table entries, */
/* verify your mail server name is in the table (add if necessary). */
/* ADD TWN6CPD 145.172.2.11 MAIL SERVER */
/* ADD WTWNAS01 145.172.1.1 LOCAL AS/400 HOST */
/* 2. Ping mail server */
/* 3. CHGSMTPA, verify AUTOSTART(*YES) and MAILROUTER(mail-svr-name) */
/* 4. ADDDIRE USRID(INTERNET SMTPRTE) + */
/* USRD('Internet SMTP gateway') SYSNAME(INTERNET) + */
/* PREFADR(NETUSRID *IBM ATCONTXT) */
/* CHGDSTA SMTPRTE(INTERNET SMTPRTE) */
/* 5. STRTCPSVR *SMTP */
/* If you changed the mail server address, you need restart SMTP*/
/* 6. Test : SNDDST TYPE(*LMSG) TOINTNET(E-mail address) + */
/* DSTD('Test message') LMSG('Test message') */
/* use the Work with Directory Entries (WRKDIRE) command to */
/* enroll you in the system directory. */
/* */
/* preventing large e-mail messages from splitting */
/* CHGPOPA MSGSPLIT(*NOMAX) */
/* *DFT size is 128k */
CMD PROMPT('E-mail Spooled File')
PARM KWD(FILE) TYPE(*NAME) MIN(1) PROMPT('Spooled +
file')
PARM KWD(EMAIL) TYPE(*CHAR) LEN(40) MIN(1) +
PROMPT('To e-mail address')
PARM KWD(JOB) TYPE(JOB) DFT(*) SNGVAL((*)) +
PROMPT('Job name')
PARM KWD(SPLNBR) TYPE(*DEC) LEN(4) DFT(*ONLY) +
SPCVAL((*ONLY -1) (*LAST -2)) +
PROMPT('Spooled file number')
JOB: QUAL TYPE(*NAME) DFT(*)
QUAL TYPE(*NAME) PROMPT('User')
QUAL TYPE(*CHAR) LEN(6) RANGE(000000 999999) +
PROMPT('Number')
A blog about IBM i (AS/400), MQ and other things developers or Admins need to know.
星期一, 11月 06, 2023
2003-07-03 如何將報表(Spooled File) 使用 e-mail 傳輸至使用者 ?(工具:ESPLF)
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言