How can I send email from PCL if any of the text values might include special characters?

Document ID : KB000055269
Last Modified Date : 14/02/2018
Show Technical Document Details

Quite often the email you wish to send would only contain the contents of Alchemist variables where you know that special characters would not be encountered. In that case, you could code your PCL to use a simple inline data method, such as this:

//EMAIL  PROC
//  FREE NOTETXT,COND
//  ALLOCATE NOTETXT,SYSOUT=(B,SMTP) 
//  OPEN NOTETXT,OUTPUT,ACCESS=SEQUENTIAL,RECFM=FB,LRECL=80,
//       BLKSIZE=6160
...SET values as required for use within email text
//  SET SUBBY = '&PCLUSERID'<<F,L>>
//  SET SUBNAME = '&ASRRID.SUBNM'<<F,F+18>>
...
//  WRITE NOTETXT,*,FORMAT=(,SUB)
HELO xxx
MAIL FROM:<ALCOE1@CYBERMATION.COM>
...
   REQUESTOR: &SUBNAME. (&SUBBY.)
...
//  CLOSE NOTETXT
//  FREE NOTETXT

However, if any of your variables might contain special characters it would be best to set the value of the text line to a variable then write that one line to the file. Continue like this one line at a time, coding the PCL to avoid symbolic substitution where necessary.

It can be especially troublesome for PCL if a creative user enters a "&" within a variable and you have coded your PCL with symbolics, e.g. using &variablename. This will prompt recursive attempts to resolve the &variables. Request Description is a notorious field for this type of thing. Double and single quotes will also cause you headaches. Here is an example of how to accommodate this possibility:

//EMAIL    PROC                                                         
//********************************************************************* 
//* EMAIL: CALLED TO SEND AN E-MAIL MESSAGE                           * 
//* EXECUTION ENVIRONMENT: ANYWHERE                                   * 
//*                                                                   * 
//* SYMBOLIC PARAMETERS:   FROM          - WHOM THE E-MAIL IS FROM    * 
//*                        TO            - ARRAY OF E-MAIL TO's       * 
//*                        CC            - ARRAY OF E-MAIL FROM'S     * 
//*                        TITLE         - TITLE OF THE E-MAIL        * 
//*                        DETAILS       - ARRAY OF DETAIL LINES      * 
//*                                                                   * 
//* RETURN CODES EXPECTED: 0  - SUCCESSFUL                            * 
//*                                                                   * 
//********************************************************************* 
// ALLOCATE NOTETXT,SYSOUT=(B,SMTP)                                    
// OPEN NOTETXT,OUTPUT,ACCESS=SEQUENTIAL,RECFM=FB,LRECL=80,            
//       BLKSIZE=6160                                                   
// SET LINE = 'HELO xxx'                               
// WRITE NOTETXT,LINE                                                  
// SET LINE = 'MAIL FROM:<&FROM@cybermation.com>'                       
// WRITE NOTETXT,LINE                                                  
...
// SET LINE = 'DESCRIPTION: ':ASRRID.DESC(1)<<1,30>>                    
// WRITE NOTETXT,LINE  
// SET LINE = '             ':ASRRID.DESC(2)<<1,30>>                    
// WRITE NOTETXT,LINE                            
...                                     
// CLOSE NOTETXT                                 
// FREE NOTETXT,COND                             
// EXIT 0

This Frequently Asked Question applies to all supported releases of ESP Alchemist.