Inside VESOFT #05 (Preprocess for Sendmail/iX)
Shawn M. Gordon

This month I decided to team up with my my fellow writer of the Inside COBOL column for a unified solution to being able to have a report email its results via Sendmail/iX at completion.

I suppose that strictly speaking you could do this in plain old MPE/iX command files, but by using STREAMX, we get some very cool submission time parameters for prompting. There are a number of things that are required to set up the parameters for sendmail.

We need to get the send to email address, the CC and the BCC addresses as well as specify the subject and a return email address. Theoretically if you were going to launch a report and email it to someone, you should probably supply your personal email address as a return address. While I prompt for it here, it would be possible to configure an email address within Security/3000 as a UDF (User Defined Field, we haven’t talked about them yet). Then we just use a function within STREAMX to return the email address into a variable based on the users session id. This solution is better, but I just haven’t done it.

A big issue with sending a report is in preserving the layout characteristics of the report. Just putting it into the body of an email will probably result in proportional fonts and misalignment of the data. I struggled with this for some time, and finally decided to convert the report to HTML (this is covered in the COBOL column more) and then attach it to the email. That is why you will see all these references to mail_sep and MIME and such.

The command file is fairly well documented, so you should just need to read through it to determine what is going on. There is a mix of :: for STREAMX and ! for MPE, because I needed things to execute at particular times. Since this particular function is in an external file, we do ::USE mail.cmd inside of our job stream to resolve it. All the stuff with a ! in front of it will end up in the final job stream that is submitted.

A funny thing at the end you will see is:

::echo MIME-Version: 1.0 >>*mt
::echo Content-Type: multipart/mixed; boundary=”!mail_sep” >>*mt
::echo >>*mt

It’s the last line that is odd. We have to at least put some information inside the body of the email or the attachements won’t work right. I messed with this a bunch to find the right mix of parameters. Sendmail has a dizzying number of features available to it. I have a thousand page book on Sendmail, and probably hurt a bit more than it helped. I’m extremely grateful to Mark Bixby for porting Sendmail, but it can be a challenge to set up and use at times.

A word of warning however. Mark has a great sample command file for sending spool files through Sendmail. Most people use these to get started, and I could never understand why no one was complaining about them. Well it turns out that the command files work just fine inside of MPE/iX, but will fail whenever you try to use them from within MPEX. Since I always am inside MPEX, I was getting very frustrated, but it did force me to read through and understand exactly what he was doing. I’m not sure of what the exact problem is with the compatibility, and it’s not an issue for me at the moment, but just keep it in mind if you choose to go this route as a learning tool.

::# Purpose: This STREAMX command file will generate a temp file that contains
::#          all of the address information needed to email a report.  Another
::#          process will append the html and spool data to the file to send 
::#          it through SENDMAIL.
::# Author : Shawn M. Gordon
::assign rm="![randomname]" + ".DATA" 
::nomsg purge !rm
::build !rm;rec=-210,,f,ascii;disc=1000000
!setvar rm,'{rm}'
::file mt={RM},old
::# Generate a unique MIME boundary string, could be anything, but this works
::assign mail_sep rht(rpt('-',36)+"!HPSUSAN!HPPIN!HPCPUMSECS",36)
::assign to = "z"
::while to <> " "
::   PROMPT STRING to = "Enter a send to email address, [enter] to end";default=" "
::   if to <> " "
::      echo To: !to >>*mt
::   endif
::assign cc = "z"
::while cc <> " "
::   PROMPT STRING cc = "Enter a CC email address, [enter] to end";default=" "
::   if cc <> " "
::      echo CC: !cc >>*mt
::   endif
::assign bcc= "z"
::while bcc <> " "
::   PROMPT STRING bcc = "Enter a BCC email address, [enter] to end";default=" "
::   if bcc <> " "
::      echo BCC: !bcc >>*mt
::   endif
::PROMPT STRING from = "Enter a return email address";default=""
::echo FROM: !from >>*mt
::PROMPT STRING subject = "Enter a subject for email";&  
         CHECK = (LEN(RTRIM(subject))) > 1;&
        CHECKERROR = "You must have a subject"  
::echo SUBJECT: !subject >>*mt
::echo MIME-Version: 1.0 >>*mt
::echo Content-Type: multipart/mixed; boundary="!mail_sep" >>*mt
::echo >>*mt
::echo This is a multi-part message in MIME format. >>*mt
!setvar mail_sep,'--{mail_sep}
!setvar send_mail,true
!file mt={RM},old