You can call the SMTPSEND2 command from a Net.Data web macro to send email. The following RPG and CL programs illustrate how to call the SMTPSEND2 command. The call to the RPG program can then be tapped into a Net.Data macro to call the program from a web browser.

The following RPGLE program calls SMTPSEND2 and will accomodate up to 5 To, CC, or BCC addresses and 1 attachment file. You can easily modify this program to allow for multiple attachments as well.

ILE RPG Sample Program TSTNETDT1R

D*****************************************************************
 C* Sample Program for Sending Email via SMTPSEND2
 C*****************************************************************
 D cmd             S           3000         INZ(' ')
 D toaddr          S           3000         INZ(' ')
 D ccaddr          S           3000         INZ(' ')
 D bccaddr         S           3000         INZ(' ')
 D quot            S              1         INZ('''')

 D*****************************************************************
 C* MAIN LINE CALCULATIONS
 C*****************************************************************
 C*** Entry Parms
 C     *ENTRY        PLIST
 C                   PARM                    InFrom          100
 C                   PARM                    InSubject       100
 C                   PARM                    InMessage      5000
 C                   PARM                    InToAddr1       100
 C                   PARM                    InToAddr2       100
 C                   PARM                    InToAddr3       100
 C                   PARM                    InToAddr4       100
 C                   PARM                    InToAddr5       100
 C                   PARM                    InCCAddr1       100
 C                   PARM                    InCCAddr2       100
 C                   PARM                    InCCAddr3       100
 C                   PARM                    InCCAddr4       100
 C                   PARM                    InCCAddr5       100
 C                   PARM                    InBCCAddr1      100
 C                   PARM                    InBCCAddr2      100
 C                   PARM                    InBCCAddr3      100
 C                   PARM                    InBCCAddr4      100
 C                   PARM                    InBCCAddr5      100
 C                   PARM                    Inattach        255
 C                   PARM                    ErrRtn            1

*                  ** Build To Email Address List
 C                   If        %trim(InToAddr1) <> ''
 C                   Eval      ToAddr = %trim(ToAddr) + ' ' + quot +
 C                             %trim(InToAddr1) + quot
 C                   Endif
 C                   If        %trim(InToAddr2) <> ''
 C                   Eval      ToAddr = %trim(ToAddr) + ' ' + quot +
 C                             %trim(InToAddr2) + quot
 C                   Endif
 C                   If        %trim(InToAddr3) <> ''
 C                   Eval      ToAddr = %trim(ToAddr) + ' ' + quot +
 C                             %trim(InToAddr3) + quot
 C                   Endif
 C                   If        %trim(InToAddr4) <> ''
 C                   Eval      ToAddr = %trim(ToAddr) + ' ' + quot +
 C                             %trim(InToAddr4) + quot
 C                   Endif
 C                   If        %trim(InToAddr5) <> ''
 C                   Eval      ToAddr = %trim(ToAddr) + ' ' + quot +
 C                             %trim(InToAddr5) + quot
 C                   Endif

*                  ** Build CC Email Address List
 C                   If        %trim(InCCAddr1) <> ''
 C                   Eval      CCAddr = %trim(CCAddr) + ' ' + quot +
 C                             %trim(InCCAddr1) + quot
 C                   Endif
 C                   If        %trim(InCCAddr2) <> ''
 C                   Eval      CCAddr = %trim(CCAddr) + ' ' + quot +
 C                             %trim(InCCAddr2) + quot
 C                   Endif
 C                   If        %trim(InCCAddr3) <> ''
 C                   Eval      CCAddr = %trim(CCAddr) + ' ' + quot +
 C                             %trim(InCCAddr3) + quot
 C                   Endif
 C                   If        %trim(InCCAddr4) <> ''
 C                   Eval      CCAddr = %trim(CCAddr) + ' ' + quot +
 C                             %trim(InCCAddr4) + quot
 C                   Endif
 C                   If        %trim(InCCAddr5) <> ''
 C                   Eval      CCAddr = %trim(CCAddr) + ' ' + quot +
 C                             %trim(InCCAddr5) + quot
 C                   Endif

*                  ** Build BCC Email Address List
 C                   If        %trim(InBCCAddr1) <> ''
 C                   Eval      BCCAddr = %trim(BCCAddr) + ' '+ quot +
 C                             %trim(InBCCAddr1) + quot
 C                   Endif
 C                   If        %trim(InBCCAddr2) <> ''
 C                   Eval      BCCAddr = %trim(BCCAddr) + ' '+ quot +
 C                             %trim(InBCCAddr2) + quot
 C                   Endif
 C                   If        %trim(InBCCAddr3) <> ''
 C                   Eval      BCCAddr = %trim(BCCAddr) + ' '+ quot +
 C                             %trim(InBCCAddr3) + quot
 C                   Endif
 C                   If        %trim(InBCCAddr4) <> ''
 C                   Eval      BCCAddr = %trim(BCCAddr) + ' '+ quot +
 C                             %trim(InBCCAddr4) + quot
 C                   Endif
 C                   If        %trim(InBCCAddr5) <> ''
 C                   Eval      BCCAddr = %trim(BCCAddr) + ' '+ quot +
 C                             %trim(InBCCAddr5) + quot
 C                   Endif

*                  ** Build SMTPSEND2 command call
 C                   Eval      CMD = 'RJSSMTP/SMTPSEND2 ' +
 C                             'FROMADDR(' + quot +
 C                             %TRIMR(InFrom) + quot + ') '  +
 C                             'SUBJECT(' + quot +
 C                             %TRIMR(InSubject) + quot + ') '  +
 C                             'MESSAGE(' + quot +
 C                             %TRIMR(InMessage) + quot + ') '  +
 C                             'TOADDR(' +
 C                             %TRIMR(ToAddr) +  ') '  +
 C                             'CCADDR(' +
 C                             %TRIMR(CCAddr) +  ') '  +
 C                             'BCCADDR(' +
 C                             %TRIMR(BccAddr) + ')'

*                  ** Add attachment to SMTPSEND2 command call
*                  ** if an attach file name was passed.
 C                   If        %trim(InAttach) <> ''
 C                   Eval      CMD = %trim(CMD) + ' ' +
 C                             'ATTACHMENT(' + quot +
 C                             %TRIMR(InAttach) + quot + ')'
 C                   Endif

*                  ** Call SMTPSEND2 command
 C                   call      'QCMDEXC'                            56
 C                   PARM                    CMD
 C                   PARM      3000          LEN              15 5

 C*                  ** Set return code for success or failure
 C                   If        *IN56 = *ON
 C*                  ** Error occurred on SMTPSEND2 call
 C*                  ** check the joblog
 C                   Eval      ErrRtn = '1'
 C                   Else
 C*                  ** Email sent successfully
 C                   Eval      ErrRtn = '0'
 C                   Endif

 C                   EVAL      *INLR = *ON
 C                   Return

 

CL Sample Program TSTNETDT1C to call the TSTNETDT1R Program

       PGM
       
       DCL        VAR(&FROMADDR) TYPE(*CHAR) LEN(100)
       DCL        VAR(&SUBJECT) TYPE(*CHAR) LEN(100)
       DCL        VAR(&MSG) TYPE(*CHAR) LEN(5000)
       DCL        VAR(&TO1) TYPE(*CHAR) LEN(100)
       DCL        VAR(&TO2) TYPE(*CHAR) LEN(100)
       DCL        VAR(&TO3) TYPE(*CHAR) LEN(100)
       DCL        VAR(&TO4) TYPE(*CHAR) LEN(100)
       DCL        VAR(&TO5) TYPE(*CHAR) LEN(100)
       DCL        VAR(&CC1) TYPE(*CHAR) LEN(100)
       DCL        VAR(&Cc2) TYPE(*CHAR) LEN(100)
       DCL        VAR(&CC3) TYPE(*CHAR) LEN(100)
       DCL        VAR(&CC4) TYPE(*CHAR) LEN(100)
       DCL        VAR(&CC5) TYPE(*CHAR) LEN(100)
       DCL        VAR(&BCC1) TYPE(*CHAR) LEN(100)
       DCL        VAR(&BCC2) TYPE(*CHAR) LEN(100)
       DCL        VAR(&BCC3) TYPE(*CHAR) LEN(100)
       DCL        VAR(&BCC4) TYPE(*CHAR) LEN(100)
       DCL        VAR(&BCC5) TYPE(*CHAR) LEN(100)
       DCL        VAR(&IFSATTACH) TYPE(*CHAR) LEN(255)
       DCL        VAR(&ERRRTN) TYPE(*CHAR) LEN(1)

/* SET PARMS FOR EMAIL SEND PROGRAM */
       CHGVAR     VAR(&FROMADDR) VALUE('richard@rjssoft.com')
       CHGVAR     VAR(&SUBJECT) VALUE('Net.Data Test')
       CHGVAR     VAR(&MSG) VALUE('This is a test message')
       CHGVAR     VAR(&TO1) VALUE('richard@rjssoft.com')
       CHGVAR     VAR(&IFSATTACH) VALUE('/REPORT.PDF')

/* PLACE CALL TO EMAIL SEND PROGRAM */
       CALL       PGM(TSTNETDT1R) PARM(&FROMADDR &SUBJECT &MSG +
                    &TO1 &TO2 &TO3 &TO4 &TO5 &CC1 &CC2 &CC3 +
                    &CC4 &CC5 &BCC1 &BCC2 &BCC3 &BCC4 &BCC5 +
                    &IFSATTACH &ERRRTN)

/* DISPLAY ERROR RETURN MESSAGE */
       IF         COND(&ERRRTN = '0') THEN(DO)
       SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Email +
                    was sent')
       ENDDO
       IF         COND(&ERRRTN = '1') THEN(DO)
       SNDPGMMSG  MSGID(CPF9898) MSGF(QCPFMSG) MSGDTA('Errors +
                    occurred while sending email. Check job log')
       ENDDO

 


Still have questions? We can help. Submit a case to Technical Support.

Last Modified On: December 10, 2016