/**   REXX                                                          **/
/** Name:    SMTPNOTE                                               **/
/** Customization:                                                  **/
/**                                                                 **/
/** HOSTNAME  HOSTNAME + DOMAINORIGIN of your TCPIP DATA file.      **/
/**                                                                 **/
    hostname = "IBMHOST.ILLWERKE.AT"                   /* 98/11/09 RT */
/**                                                                 **/
/** SMTPNODE  The NJE node on which the SMTP address space or       **/
/**           virtual machine runs. Typically HOSTNAME and SMTPNODE **/
/**           will have the same value.  In the case where SMTPNOTE **/
/**           is being used on a NJE network in conjunction with a  **/
/**           TCP-NJE gateway, the value of SMTPNODE will be the    **/
/**           NJE node name of the TCP-NJE gateway.                 **/
/**                                                                 **/
    smtpnode = "SMTP"                                  /* 98/11/09 RT */
/**                                                                 **/
/** SMTPJOB   The name of the address space or virtual machine in   **/
/**           which SMTP runs at SMTPNODE.  Usually this is "SMTP". **/
/**                                                                 **/
    smtpjob = "SMTP"
/**                                                                 **/
/** TIMEZONE   The time zone which appears in the "Date:" stamp     **/
/**            of the RFC 822 header.                               **/
/**                                                                 **/
    timez1 = "+0100"
    timez2 = "+0200"
/**                                                                 **/
/** TEMPDSN   The name of the temporary dataset used to store the   **/
/**           contents of notes being created.  This can be any     **/
/**           arbitrary dataset name but it must end with '.TEXT'.  **/
/**           DO NOT put single quotes around the name, i.e. use a  **/
/**           fully qualified dataset name, as this will result in  **/
/**           multiple TSO users using the same temporary dataset.  **/
/**                                                                 **/
    tempdsn = "SMTPNOTE TEXT A"                        /* 98/11/09 RT */
    tempdsn2= "SMTPNOTE DATA A"                        /* 98/11/09 RT */
/**                                                                 **/
/** added code for temp name so it would be unique    MOD           **/
/*+     ADDRESS TSO "ALLOC FILE(XX) T SPACE(91) ",                   */
/*+      " LRECL(255) DSORG(PS) RECFM(V B) BLKSIZE(3120) NEW DELETE" */
/*+    tempdsn = listdsi(xx file)                                    */
/*+    ADDRESS TSO "FREE FILE(XX) "                                  */
/*+    PARSE VAR SYSDSNAME v "." w "." x "." y "." z                 */
/*+    tempdsn = w"."y"."z".TEXT"                                    */
/*+    tempdsn2 = w"."y"."z".DATA"                                   */
/*+                if sysvar('syspref') = "" then do                 */
/*+                   tempdsn = userid()"."tempdsn                   */
/*+                   tempdsn2 = userid()"."tempdsn2                 */
/*+                   end                                            */
/** End Customization section                                       **/
/*********************************************************************/
trace o
parse arg parms
parse source system .                /* find out where we are      */
if parms = '?' then do
   if system = 'TSO' then 'HELP SMTPNOTE'   /* get the normal help */
                     else say "EZA5591E HELP ONLY AVAILABLE UNDER TSO"
   exit                              /* and then exit              */
end
to  = ''
cc  = ''
nocc = ''
mimedoc =''
boundary = 'gc0y0pkb9ex'
encode = '7bit'                 /* default file encoding */
bcc=''
ext=''
filea=''
rp = ''
fr = ''
imp =''
fix =''
enrich=''
nofill=''
su = ''
da = ''
debug = ''
batch = ''
parms = translate(parms,'B5'x,'u'); /* transl. at sign    98/11/10 RT */
i = 1                                 /* get number of parms.      */
j = words(parms)                      /* get number of parms.      */
do while i<=j                         /* Scan all parms.           */
  parmword = word(parms,i)
  parse var parmword parm '(' value ')' leftover
  select
    when abbrev('TO',translate(parm),1) then do
         myindex = wordindex(parms,i)
         tovar = substr(parms,myindex)
         too = to
         parse var tovar parm "(" to ")" parms
         if (to = "") then do
            errcode=0013
            call errexit
            exit 1
         end
         to = too to
         i = 0
         j = words(parms)
    end
    when abbrev('REPLYTO',translate(parm),1) then do
         myindex = wordindex(parms,i)
         rpvar = substr(parms,myindex)
         parse var rpvar parm "(" rp ")" parms
         if (rp = "") then do
            errcode=0016
            call errexit
            exit 1
         end
         i = 0
         j = words(parms)
    end
    when abbrev('FROM',translate(parm),3) then do
         myindex = wordindex(parms,i)
         frvar = substr(parms,myindex)
         parse var frvar parm "(" fr ")" parms
         if (fr = "") then do
            errcode=0016
            call errexit
            exit 1
         end
         i = 0
         j = words(parms)
    end
    when abbrev('IMPORTANCE',translate(parm),1) then do
         myindex = wordindex(parms,i)
         impvar = substr(parms,myindex)
         parse var impvar parm "(" imp ")" parms
         imp=translate(imp)
         if (imp = "") ! ,
         ((imp^='LOW') &(imp^='HIGH')&(imp^='NORMAL')) then do
            errcode=0018
            call errexit
            exit 1
         end
         i = 0
         j = words(parms)
    end
    when abbrev('ENRICH',translate(parm),1) then do
         enrich = 'enriched'
         end
    when abbrev('NOFILL',translate(parm),3) then do
         nofill = '<nofill>'
         end
    when abbrev('HTML',translate(parm),1) then do
         enrich = 'html'
         end
    when abbrev('FIXED',translate(parm),3) then do
         fix = 'fixed'
         end
    when abbrev('FILE',translate(parm),3) then do
    if (pos('(',value) > 0) then do
                                 value = value !! ')'
                                 end
    if (pos('(',value) > 0 & pos("'",value) > 0) then do
                                 value = value !! "'"
                                 end
 
    filea = filea !! ' ' !! value
    if (value = "") then do
       errcode=0019
       call errexit
       exit 1
    end
    parse var leftover . ',EXT=' extx ')'
    if extx = '' then parse var leftover . ',ext=' extx ')'
    if extx = '' then extx = 'txt'
    ext = ext !! ' ' !! extx
    end
    when abbrev('BCC',translate(parm),2) then do
         myindex = wordindex(parms,i)
         bccvar = substr(parms,myindex)
         bcco = bcc
         parse var bccvar parm "(" bcc ")" parms
         if (bcc = "") then do
            errcode=0020
            call errexit
            exit 1
         end
         bcc = bcco bcc
         i = 0
         j = words(parms)
    end
    when abbrev('CC',translate(parm),2) then do
         myindex = wordindex(parms,i)
         ccvar = substr(parms,myindex)
         ccc = cc
         parse var ccvar parm "(" cc ")" parms
         if (cc = "") then do
            errcode=0014
            call errexit
            exit 1
         end
         cc = ccc cc
         i = 0
         j = words(parms)
    end
    when abbrev('NOCC',translate(parmword),3) then nocc = 'NOCC'
    when abbrev('SUBJECT',translate(parm),1) then do
         myindex = wordindex(parms,i)
         subj = substr(parms,myindex)
         if substr(value,1,1) = "'" then do
             parse var subj parm "'" su "'" parms
             if substr(parms,1,1) = ')' then parms = substr(parms,2)
         end
         else
            if substr(value,1,1) = '"' then do
               parse var subj parm '"' su '"' parms
               if substr(parms,1,1) = ')' then parms = substr(parms,2)
            end
            else parse var subj parm "(" su ")" parms
         i = 0
         j = words(parms)
    end
    when abbrev('DATASET',translate(parm),2) then do
 
/*+ /+ If parenthesis is found then assume dataset is PDS and  @01A */
/*+ /+ not sequential so append closing parenthesis            @01A */
/*+ if (pos('(',value) > 0) then do                          /+@01A */
/*+                              value = value !! ')'        /+@01A */
/*+                              end                         /+@01A */
/*+ if (pos('(',value) > 0 & pos("'",value) > 0) then do     /+@04A */
/*+                              value = value !! "'"        /+@04A */
/*+                              end                         /+@04A */
    da = translate(value,' ','.')                      /* 98/11/09 RT */
    if (da = "") then do
       errcode=0015
       call errexit
       exit 1
    end
    end
    when abbrev('DEBUG',translate(parmword),2) then debug = 'DEBUG'
    when abbrev('BATCH',translate(parmword),2) then batch = 'BATCH'
    otherwise
      errparm=word(parms,i)
      errcode=0010
      call errexit
      exit 1
    end
    i = i+1
end
if (batch = "BATCH") then
   if (da = "") then do
      errcode=0011
      call errexit
      exit 1
   end
if debug = "DEBUG" then do
    trace i
/*+ msg("ON") */
end
/*+ else msg("OFF") */
errcode = 0
recovlvl = 0
/*********************************************************************/
/** If NOCC was specified then check for conflict with the CC       **/
/** parameter.                                                      **/
/*********************************************************************/
if nocc = 'NOCC' then do
    if cc ^= '' then do
        errcode = 012
        call ERREXIT
    end
end
/*********************************************************************/
/** copy the specified dataset (DA) to the temporary dataset,       **/
/** or allocate it.    Any previous data is deleted first.          **/
/*********************************************************************/
errcode = 0
/*+ if sysdsn(tempdsn) ^= "DATASET NOT FOUND" then do */
    'SET CMSTYPE HT'                                   /* 98/11/09 RT */
    address command 'ERASE' tempdsn                    /* 98/11/09 RT */
    zrc = rc                                           /* 98/11/09 RT */
    'SET CMSTYPE RT'                                   /* 98/11/09 RT */
    rc = zrc                                           /* 98/11/09 RT */
/*+ address TSO "delete" tempdsn "purge" */
    if rc ^= 0 & rc ^= 28 then do                      /* 98/11/09 RT */
        errcode = 006
        call ERREXIT
    end
/*+ end        */
if da ^= "" then do
/*+ sub1 = sysdsn(da)                */
/*+ if sub1 ^= "OK" then do          */
/*+    errcode = 009                 */
/*+    call  ERREXIT                 */
/*+ end                              */
/*+ address TSO "ALLOC DA("tempdsn") LIKE("da,                      */
/*+  ") LRECL(255) DSORG(PS) RECFM(V B) BLKSIZE(3120) NEW CATALOG" */
/*+ if rc ^= 0   then do                                   /+@02A*/
/*+ /+ A return code of 12 is a general allocation failure   @02A*/
/*+ /+ could be protected error or record length problem     @02A*/
/*+ /+ sub1 = "PROTECTED DATASET"                            @02R*/
/*+    errcode = 008                                       /+@02C*/
/*+    call ERREXIT                                        /+@02A*/
/*+ end                                                    /+@02A*/
/*+ added code to allow 2 or more jobs to repro       MOD           **/
/*+ same data set - removed old repro command         MOD           **/
/*+ ADDRESS TSO "ALLOC DS("DA") FILE(XX) SHR"                        */
/*+ address TSO "REPRO INFILE(XX) ODS("tempdsn")"                    */
    address command 'COPYFILE' da tempdsn              /* 98/11/09 RT */
    if rc ^= 0 then do                                     /*@02C*/
       sub1 = "COPYING ERRORS DETECTED"                    /*@02C*/
       errcode = 009                                       /*@02C*/
       call ERREXIT
    end
/** Free allocation for REPRO                         MOD           **/
/*+ADDRESS TSO "FREE FILE(XX) "                                      */
end
/*+else do                                                           */
/*+ address TSO "alloc da("tempdsn,                                  */
/*+   ") new catalog dsorg(ps) recfm(v b)" ,                         */
/*+   "blksize(3120) lrecl(255) tracks space(1,1)"                   */
/*+ if rc ^= 0 then do                                               */
/*+     errcode = 002                                                */
/*+     call ERREXIT                                                 */
/*+ end                                                              */
/*+ address TSO "free da("tempdsn")"                                 */
/*+ end                                                              */
/*********************************************************************/
/** Build the date stamp.                                           **/
/*********************************************************************/
/* the first line prints the century, the second removes it          */
/* Added code Daylight Saving Time adj of timezone MOD               */
/* Daylight saving time is from first Sunday in April till           */
/* last Sunday in October (@ 2 am which I did not included)          */
timezone = timez1
do ix=1       /* Force a loop so the leave can be used         */
  dateu = date('U')
  parse var dateu mm '/' dd '/' .
  if ( (mm > 4) & (mm < 10) ) then do    /* All months between */
      timezone = timez2                  /* are EDT            */
      leave ix
      end
/* Months outside are all EST */
  if ( (mm < 4) ! (mm > 10) ) then leave ix
/* Only month 4 and 10 are look at to find where we are at */
  if mm = 4 then do
      /* After the 7 we have to be in EDT as we must have   */
      /* had a Sunday                                       */
      if dd >= 7 then do
        timezone = timez2
        leave ix
        end
      datew = date('W')
      if datew = 'Sunday'    then u=1
      if datew = 'Monday'    then u=2
      if datew = 'Tuesday'   then u=3
      if datew = 'Wednesday' then u=4
      if datew = 'Thursday'  then u=5
      if datew = 'Friday'    then u=6
      if datew = 'Saturday'  then u=7
/* When a Sunday occurs the days number (1 2 3) less      */
/* the value of u will be > zero letting us know that     */
/* a Sunday has occured. if 4/1 is a Thurday then         */
/* sunday will be 4/4                                     */
      k = dd -u
      if k < 0 then leave ix
      else do
        timezone = timez2
        leave ix
        end
      end
/* mm is equal to 10 */
/* Before the 25 we must still be in EDT   */
  if dd < 25 then do
      timezone = timez2
      leave ix
      end
  datew = date('W')
  if datew = 'Sunday'    then u=7
  if datew = 'Monday'    then u=6
  if datew = 'Tuesday'   then u=5
  if datew = 'Wednesday' then u=4
  if datew = 'Thursday'  then u=3
  if datew = 'Friday'    then u=2
  if datew = 'Saturday'  then u=1
/* u is the number of days till the next Sunday    */
/* we then add this to the date and see if this    */
/* Sunday will be in the month. If yes then EDT    */
/* is still if effect (k <= 31)                    */
  k = dd + u
  if k > 31 then leave ix
  timezone = timez2
/* Break the do loop otherwise we would loop forever */
  leave ix
end
date = date("n")" "time()" "timezone
date = subword(date,1,2)               !! ,   /* dd mon */
       " "                             !! ,
       strip(substr(word(date,3),3,4)) !! ,   /* yy */
       " "                             !! ,
       subword(date,4)                        /* time and zone  @03C */
/*********************************************************************/
/** If the TO parameter was not specified then prompt for           **/
/** multiple destination mailboxes.                                 **/
/*********************************************************************/
if to = "" then do
    if batch = "BATCH" then do
      errcode = 001
      call ERREXIT
    end
    else do
      say "TO:"
      do tocnt=1 by 1 until to.tocnt = ""
        parse pull to.tocnt
      end
      tocnt = tocnt - 1
    end
end
else do
  j = words(to)
  do i=1 to j
    to.i = word(to,i)
  end
  tocnt=i-1
end
/*********************************************************************/
/** If less than 1 destination was specified then report the        **/
/** error.                                                          **/
/*********************************************************************/
if tocnt < 1 then do
    errcode = 001
    call ERREXIT
end
/*********************************************************************/
/** If the CC parameter was not specified then prompt for           **/
/** multiple carbon copy mailboxes.                                 **/
/*********************************************************************/
if cc = "" then do
    if (batch = "BATCH") ! (nocc = "NOCC")  then cccnt = 0
    else do
      say "CC:"
      do cccnt = 1 by 1 until cc.cccnt= ""
        parse pull cc.cccnt
      end
      cccnt = cccnt - 1
    end
end
else do
  do i=1 to words(cc)
    cc.i = word(cc,i)
  end
  cccnt = i-1
end
if bcc ^= "" then do
  do i=1 to words(bcc)
    bcc.i = word(bcc,i)
  end
  bcccnt = i-1
end
if filea ^= "" then do
  do i=1 to words(filea)
    filea.i = translate(word(filea,i),' ','.')         /* 98/11/10 RT */
    ext.i = word(ext,i)
  end
  fileacnt = i-1
  extcnt = i-1
end
/*********************************************************************/
/** If the SU parameter was not specified then prompt for           **/
/** the subject.                                                    **/
/*********************************************************************/
if su = "" then do
    if batch = "BATCH" then su = ""
    else do
      say "SUBJECT:"
      parse pull su
    end
end
/*********************************************************************/
/** Invoke the TSO editor for the user. If a dataset has been       **/
/** imported then stay in EDIT mode.  If this is a new note then go **/
/** into INPUT mode.  Once the user escapes from INPUT mode, write  **/
/** out some help messages and wait for the appropriate termination **/
/** string.  The user can use any of the editor's commands at this  **/
/** time.                                                           **/
/*********************************************************************/
errcode = 0
if batch^="BATCH" then do
/*********************************************************************/
/** Build the RFC 822 header by using the editor and inserting      **/
/** the data line by line into the note file.    Have the editor    **/
/** save the note before proceeding.                                **/
/*********************************************************************/
/**    use ispf edit if possiable                     MOD           **/
/*+if ((sysvar("SYSISPF") = "ACTIVE") & ,                            */
/*+    (sysvar("SYSENV") = "FORE")) then do                          */
/*+  say 'Be sure to save your data before ending the EDIT session'  */
/*+  ADDRESS ISPEXEC "EDIT DATASET("tempdsn")"                       */
/*+  recovlvl = 1                                                    */
/*+  if errcode ^= 0 then do                                         */
/*+      errcode = 004                                               */
/*+      call ERREXIT                                                */
/*+  end                                                             */
/*+end                                                               */
/*+else do                                                           */
/*+   say                                                            */
      queue 'MSG ENTER "SAVE" TO SAVE THE NOTE.'       /* 98/11/14 RT */
/*+   address TSO "edit" tempdsn "text nonum imode"                  */
      address command 'XEDIT' tempdsn;                 /* 98/11/14 RT */
      recovlvl = 1
      if errcode ^= 0 then do
          errcode = 004
          call ERREXIT
      end
/*+end     */
  say 'ENTER "SEND" TO SEND THE NOTE.'
  say 'ENTER "CANCEL" TO TERMINATE WITHOUT SENDING THE NOTE.'
  parse upper pull resp
  pointer = find("SEND CANCEL",resp)
  if pointer = 0 then do
      errcode = 004
      call ERREXIT
  end
/*********************************************************************/
/** If the user entered CANCEL then use the error exit with         **/
/** the appropriate error number.                                   **/
/*********************************************************************/
  if pointer = 2 then do
      errcode = 003
      call ERREXIT
  end
  recovlvl = 2
  if errcode ^= 0 then do
      errcode = 004
      call ERREXIT
  end
end
/** Process outout to one new file                    MOD           **/
smtphead.1 = "helo "hostname
p=1
if (fr = "") then do
    p=p+1
    smtphead.p = "mail from:<"userid()"@"hostname">"
    end
else do
    p=p+1
    smtphead.p = "mail from:<"fr">"
    end
do i=1 by 1 while i <= tocnt
    p=p+1
    smtphead.p = "rcpt to:<"to.i">"
end
do i=1 by 1 while i <= cccnt
    p=p+1
    smtphead.p = "rcpt to:<"cc.i">"
end
do i=1 by 1 while i <= bcccnt
    p=p+1
    smtphead.p = "rcpt to:<"bcc.i">"
end
p=p+1
smtphead.p = "data"
p=p+1
smtphead.p = "Date:     "date
if (fr = "") then do
    p=p+1
    smtphead.p = "From:     "userid()"@"hostname
    end
else do
    p=p+1
    smtphead.p = "From:     "fr
    end
if rp ^= ""  then do
    p=p+1
    smtphead.p = "Reply-To: " rp
    end
conchr = ""
if tocnt > 1
  then
    conchr = ","
p=p+1
smtphead.p = "To:       "to.1!!conchr
i = 2
do while i <= tocnt
    if i = tocnt then conchr = ""
    p=p+1
    smtphead.p = "          "to.i!!conchr
    i = i + 1
end
if cccnt ^= 0 then do
    conchr = ""
    if cccnt > 1 then conchr = ","
    p=p+1
    smtphead.p = "Cc:       "cc.1!!conchr
    i = 2
    do while i <= cccnt
        if i = cccnt then conchr = ""
        p=p+1
        smtphead.p = "          "cc.i!!conchr
        i = i + 1
        end
    end
if su ^= "" then do
    p=p+1
    smtphead.p = "Subject:  "su
    end
if imp ^= '' then do
    p=p+1
    smtphead.p = "Importance: "imp
    end
smtphead.0 = p
smtpin = tempdsn;                                      /* 98/11/09 RT */
smtpout= tempdsn2;                                     /* 98/11/09 RT */
/*+ address TSO "FREE FILE(SMTPOUT,SMTPIN)"                 */
/*+ address TSO "ALLOC FILE(SMTPIN) DSN("tempdsn") SHR"     */
/*+ address TSO "ALLOC FILE(SMTPOUT) DSN("tempdsn2") LIKE("tempdsn,  */
/*+  ") LRECL(255) DSORG(PS) RECFM(V B) BLKSIZE(0) NEW CATALOG"      */
"execio" smtphead.0 "diskw" SMTPOUT "(STEM SMTPHEAD."  /* 98/11/09 RT */
if fix ^= '' then do
    nofill = 'nofill'
    enrich = 'enriched'
    end
if (enrich = '') & (nofill ^= '') then enrich = 'enriched'
if ((enrich ^='') ! (filea ^='')) then do
    mimedoc = 'yes'
    mimehead.1 = 'Mime-Version: 1.0'
    mimehead.2 = 'Content-type: multipart/mixed;'
    mimehead.3 = '              boundary="'boundary'"'
    mimehead.4 = ' '
    mimehead.5 = 'This message is in MIME format'
    mimehead.6 = '--'boundary
    if enrich = '' then enrich='plain'
    mimehead.7 = "Content-Type: text/"enrich
    mimehead.0 = 7
    "execio" mimehead.0 "diskw" SMTPOUT,               /* 98/11/09 RT */
    "(STEM MIMEHEAD."                                  /* 98/11/09 RT */
    end
smtpbody.1 = ' '
p=1
if nofill ^= '' then do
    p = p +1
    smtpbody.p = "<nofill>"
    end
if fix ^= '' then do
    p = p +1
    smtpbody.p = "<fixed>"
    end
smtpbody.0 = p
"execio" smtpbody.0 "diskw" SMTPOUT "(STEM SMTPBODY."  /* 98/11/09 RT */
"execio * diskr" SMTPIN  "(STEM SMTPDATA. FINIS"       /* 98/11/09 RT */
"execio" smtpdata.0 "diskw" SMTPOUT "(STEM SMTPDATA."  /* 98/11/09 RT */
/*+ ADDRESS TSO "FREE FILE(SMTPIN)" */
drop smtpdata.
if filea ^='' then do
    mimebody.1 = ' '
    mimebody.2 = ' '
    mimebody.3 = '--'boundary
    mimebody.4 = 'Content-Type: text/plain;'
    mimebody.5 = '              charset="US-ASCII";'
    mimebody.6 = '              name="'xxxxxx'"'  /* refifined later */
    mimebody.7 = 'Content-Transfer-Encoding:' encode
    mimebody.8 = ' '
    mimebody.0 = 8
    do i=1 to fileacnt
        dsna = strip(filea.i,"B","'")
        mimebody.6 = '              name="' !!,        /* 98/11/10 RT */
          word(dsna,1)'.'ext.i'"'                      /* 98/11/10 RT */
        "execio" mimebody.0 "diskw" SMTPOUT,           /* 98/11/09 RT */
        "(STEM MIMEBODY."                              /* 98/11/09 RT */
/*+     address TSO 'ALLOCATE FI(SMTPTEMP) DA('filea.i') SHR'  */
        "execio * diskr" filea.i "(STEM FILEIN. FINIS" /* 98/11/09 RT */
/*+     address TSO 'FREE FI(SMTPTEMP)'                        */
        "execio" filein.0 "diskw" SMTPOUT,             /* 98/11/09 RT */
        "(STEM FILEIN."                                /* 98/11/09 RT */
        drop filein.
    end
end
if mimedoc = 'yes' then do
    mimetrail.1 ="--"boundary"--"
    mimetrail.0 = 1
    "execio" mimetrail.0 "diskw" SMTPOUT,              /* 98/11/09 RT */
    "(STEM MIMETRAIL."                                 /* 98/11/09 RT */
    end
"execio 0 diskw" SMTPOUT "(STEM MIMETRAIL. FINIS"      /* 98/11/09 RT */
/*+ ADDRESS TSO "FREE FILE(SMTPOUT)"                 */
errcode = 0
recovlvl = 1
if errcode ^= 0 then do
    errcode = 004
    call ERREXIT
end
/*********************************************************************/
/** Transmit the note to SMTP address space, which may be           **/
/** on this system or some other on the NJE network.    Finally,    **/
/** delete the temporary dataset.                                   **/
/*********************************************************************/
/*+ address TSO "transmit" smtpnode"."smtpjob ,         */
/*+  "dataset("tempdsn2") noepilog nolog noprolog"      */
'EXEC SENDFILE' tempdsn2 smtpnode '(NOLOG'             /* 98/11/10 RT */
if rc ^= 0 then do
    errcode = 005
    call ERREXIT
end
recovlvl = 4
/*+ address TSO "delete" tempdsn "purge"    */
/*+ address TSO "delete" tempdsn2 "purge"   */
address command 'ERASE' tempdsn                        /* 98/11/09 RT */
if rc ^= 0 then do
    errcode = 006
    call ERREXIT
end
address command 'ERASE' tempdsn2                       /* 98/11/09 RT */
if rc ^= 0 then do                                     /* 98/11/09 RT */
    errcode = 006                                      /* 98/11/09 RT */
    call ERREXIT                                       /* 98/11/09 RT */
end                                                    /* 98/11/09 RT */
exit
ERREXIT:
/*********************************************************************/
/** Error exit:    Use the recovery level to determine what         **/
/** steps to take.    These can be save the current contents of     **/
/** the note, discard the current contents of the note, or          **/
/** delete the existing temporary dataset.                          **/
/*********************************************************************/
if recovlvl = 1 then
/*+ address TSO "save"   */
    nop                                                /* 98/11/14 RT */
else
    if recovlvl = 2 then
/*+     address TSO "nosave" */
        nop                                            /* 98/11/14 RT */
    else
        if recovlvl = 3 then
            address TSO "delete" tempdsn "purge"
/*+         address TSO "delete" tempdsn "purge" */
            address command 'ERASE' tempdsn            /* 98/11/09 RT */
/*********************************************************************/
/** Write out the error number and message.                         **/
/*********************************************************************/
select
   when errcode = 001 then
     say "EZA5575E NO DESTINATION SPECIFIED FOR NOTE"
   when errcode = 002 then
     say "EZA5576E UNABLE TO ALLOCATE TEMPORARY DATASET '"tempdsn"'"
   when errcode = 003 then
     say "EZA5577I NOTE CANCELLED"
   when errcode = 004 then
     say "EZA5578I UNABLE TO EDIT TEMPORARY DATASET '"tempdsn"'"
   when errcode = 005 then
     say "EZA5579E UNABLE TO TRANSMIT DATA TO '"smtpjob",
' AT '"smtpnode"'"
   when errcode = 006 then
     say "EZA5580E UNABLE TO DELETE TEMPORARY DATASET '"tempdsn"'"
   when errcode = 007 then
     say "EZA5581E CONFLICTING PARAMETERS 'DATASET' AND 'REUSE'"
   when errcode = 008 then
     say "EZA5582E UNABLE TO USE DATASET '"da"'"
   when errcode = 009 then
     say "EZA5583E UNABLE TO USE DATASET '"da"'," sub1
   when errcode = 010 then
     say "EZA5584E INVALID PARAMETER, "parm
   when errcode = 011 then
     say "EZA5585E BATCH PARAMETER REQUIRES DATASET PARAMETER"
   when errcode = 012 then
     say "EZA5586E CONFLICTING PARAMETERS 'CC' AND 'NOCC'"
   when errcode = 013 then
     say "EZA5587E NO VALUE FOR PARAMETER 'TO'"
   when errcode = 014 then
     say "EZA5588E NO VALUE FOR PARAMETER 'CC'"
   when errcode = 015 then
     say "EZA5589E NO VALUE FOR PARAMETER 'DATASET'"
   when errcode = 016 then
     say "EZA5589E NO VALUE FOR PARAMETER 'REPLYTO'"
   when errcode = 017 then
     say "EZA5589E NO VALUE FOR PARAMETER 'FROM'"
   when errcode = 018 then
     say "EZA5589E NO/invalid VALUE FOR PARAMETER 'IMPORTANCE'" imp
   when errcode = 019 then
     say "EZA5589E NO VALUE FOR PARAMETER 'FILE'"
   when errcode = 020 then
     say "EZA5587E NO VALUE FOR PARAMETER 'BCC'"
   when errcode = 999 then
        say "EZA5590S UNRECOVERABLE ERROR"
   otherwise
     say "EZA5590S UNKNOWN ERROR CODE '"errcode"'"
end /* select */
/**      change exit to set return code of 12         MOD           **/
exit 12
