The following sample programs include a CL program and an ILE RPG (V5R1 Free Format Calcs) program to create a text message and email the message from the iSeries using the SMTPTEXT command:
PGM /***************************************************************/ /* GO TO ERROR HANDLER IF ERRORS OCCUR */ /***************************************************************/ MONMSG MSGID(CPF0000) EXEC(GOTO CMDLBL(ERRORS)) /***************************************************************/ /* CREATE TEMPORARY AS/400 FILE TO HOLD MESSAGE TEXT */ /* CLEAR THE MEMBER TO MAKE SURE WE'RE READY TO GO */ /***************************************************************/ CRTPF FILE(QTEMP/SMTPMSG) RCDLEN(512) + OPTION(*NOLIST *NOSRC) MAXMBRS(*NOMAX) MONMSG MSGID(CPF0000) /***************************************************************/ /* RUN RPG PROGRAM TO CREATE TEXT MESSAGE IN FILE */ /***************************************************************/ OVRDBF FILE(SMTPMSG) TOFILE(QTEMP/SMTPMSG) CALL PGM(TESTTEXT1R) DLTOVR FILE(SMTPMSG) /***************************************************************/ /* CALL SMTPTEXT TO SEND THE TEXT MESSAGE */ /* AUTOMATICALLY CLEAR THE WORK FILE AFTER EMAILING */ /***************************************************************/ SMTPTEXT TOADDR([email protected]) FROMADDR(*DEFAULT) + SUBJECT('This is a test text message') + MSGFILE(SMTPMSG) MBR(*FIRST) CLRMBR(*YES) + SMTPHOST(*DEFAULT) CONTYPE('text/plain') RETURN /********************************************************************/ /* HANDLE ERRORS */ /********************************************************************/ ERRORS: /* SEND EXIT MESSAGE ON ERROR */ SNDPGMMSG MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Errors + occurred while creating email') + MSGTYPE(*ESCAPE) ENDPGM --------------------------------- End of CL Sample Program ----------------------------------------- --------------------------------- Begining of RPG /FREE Sample Program ----------------------------------------- H***************************************************************** H* Program description H* H* This program will write a test message to a physical file. H* The text message will be later emailed using the SMTPTEXT H* CL command. H* H* Copyright (c) 2001 RJS Software Systems Inc. H* ALL RIGHTS RESERVED H***************************************************************** FSmtpmsg IF A F 512 Disk Infds(Inp1ds) * Input data structure D Inp1ds DS D $$Rrn1 397 400B 0 D Count S 2 0 D CRLF S 2A Inz(X'0D25') D Msgtext S 512A D Newline S 2A Inz(X'25') D Null S 1A Inz(X'00') D Pagebreak S 1A Inz(X'0C') /free // WritePage Number 1 Msgtext= 'Page 1' + Newline; Except Writemsg; // Write Initial text line Msgtext= 'Thisis a long text message illustrating how to create a + textline in RPG' + Newline; Except Writemsg; // Use a loop to write 10 text lines For Count = 1 to 10 ; Msgtext= 'This is a text line' + Newline; Except Writemsg; Endfor; // Write a page break // **Note: Not all PC mail clients will recognize page // breaks in multi-page text messages. Msgtext= Pagebreak+ CRLF ; Except Writemsg; // Writea page break message Msgtext= 'A page break was written above. Not all mail clients will - recognizepage breaks.' + Newline; Except Writemsg; // Writepage number 2 Msgtext= 'Page 2' + Newline; Except Writemsg; // Write a URL Msgtext= 'Web Link to SMTP/400: ' + 'http://www.rjssoft.com/smtp400.htm' + Newline; Except Writemsg; // Writea Blank line Msgtext= ' '+ Newline; Except Writemsg; // Use a loop to write another 10 text lines For Count = 1 to 10 ; Msgtext= 'This is a text line' + Newline; Except Writemsg; Endfor; // Return to caller *INLR = *On ; Return ; /end-free O******************************************************************* O* Message Output to Message Member O******************************************************************* OSMTPMSG EADD WriteMsg O MsgText 512
Still have questions? We can help. Submit a case to Technical Support.