Send email with attachment on Mainframe using JCL

How to send SMTP email from Mainframe environment

If you have worked on the mainframe, you will probably be generating lots of reports but sending email reports to stakeholders in an automated way using SMTP is a big trouble.

In theory this is very simple task but actual implementation is often time taking due to various factors such as site settings, SMTP settings and of course the data that you want to send. So let’s see how we can get this done quickly. Make sure pay attention to details including blank lines as those are very important.

JCL to send email using IKJEFT01

Copy below JCL to a PDS member:

//JOBNAME JOB (@),'EMAIL-JCL',
//  MSGCLASS=X,CLASS=1,NOTIFY=@
//STEP1  EXEC PGM=IKJEFT01
//SYSTERM DD DUMMY
//SYSPROC DD DUMMY 
//SYSTSIN DD DSN=XMIT.PARMS,DISP=SHR
//XMITDD  DD DSN=SMTP.PARMS,DISP=SHR
//      DD DSN=ATTACH.DSN,DISP=SHR
//      DD DSN=QUIT.DSN,DISP=SHR
//SYSTSPRT  DD SYSOUT=*
//SYSPRINT  DD SYSOUT=*
/* END OF JCL

 

Contents of XMIT.PARMS

XMIT SITE.SMTP DDNAME(XMITDD) NONOTIFY NOLOG

Replace SITE with the actual name of your SITE or LPAR which has SMTP setup

Contents of SMTP.PARMS

HELO SITE
MAIL FROM: <FROM@YOURSITE.COM>
RCPT TO : <YOU@YOURSITE.COM>
DATA
TO: <YOU@YOURSITE.COM>
SUBJECT: Attached is your report
MIME-VERSION: 1.0
CONTENT-TYPE: MULTIPART/MIXED; BOUNDARY="TECHNOLOGY CENTRAL"
   

--TECHNOLOGY CENTRAL
CONTENT TYPE: TEXT/HTML
  
Your Email body goes here
  
--TECHNOLOGY CENTRAL
CONTENT-TYPE: MULTIPART/MIXED;CHARSET=UTF-8
CONTENT-DISPOSITION: ATTACHMENT; FILENAME=Daily_Report.txt
CONTENT-TRANSFER-ENCODING: 8Bit
  

Replace SITE on line 1 with the actual name of your SITE or LPAR which has SMTP setup.

Also make sure blank lines are present including last line.

ATTACH.DSN is the attachment dataset. That is, it contains the contents which you want in the attachment.

Contents of QUIT.DSN

.
QUIT
As a rule, always have a blank line after the content headers, otherwise email delivery will have issues.
Also, in the attachment file/data , make sure no NULL characters(x’00’) are present. SMTP stops transfer at NULL bytes and moves to next data line, so you will have missing data in that case.
Some sites may enforce valid email, so use valid FROM and TO email address.

 

JCL to send email using IEBGENER utility

 

You can also use IEBGENER for sending emails like below. Dataset contents will be same as above

//STEP1  EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSOUT DD SYSOUT=*
//SYSUT2 DD SYSOUT=(B,SMTP)
//SYSUT1 DD DSN=SMTP.PARMS,DISP=SHR
//      DD DSN=ATTACH.DSN,DISP=SHR
//      DD DSN=QUIT.DSN,DISP=SHR
/* END OF JCL

Caution:
  • SMTP has restrictions that e-mail only consist of valid ASCII characters and can’t handle binary values embedded in an e-mail. If you have data having binary or null values , then either base64 encode them using
Content-Transfer-Encoding: base64

or zip and transfer them using a ZIP utility.

  • Make sure file length for all 3 files i.e SMTP.PARMS , ATTACH.DSN, QUIT.DSN are same. Most likely your report/attachment file length can not be changed. In that case create other 2 files with same length as attachment file.

Other questions this post should help answer:

  • How to send email with attachment from mainframe JCL using SMTP
  • Data loss with email attachment from mainframe
  • Issues with sending email from mainframe using JCL.

External Links: http://www-01.ibm.com/support/docview.wss?uid=swg21512178

Any questions or issues, use the comments below to contact me.

Leave a Reply

Technology Central © 2014 - 2018 | Privacy Policy | Website Terms & Conditions