Send email through JCL - Mainframe with an attachment

In our previous tutorial we have learned how to send an email from mainframe JCL. This part of the tutorial explains how we can send an email with an attachment from mainframe with JCL code.

IBM utility IEBGENER is used to send an email from JCL. The following code explains how we can send an email with an attachment

Example Code



//EMAILATT JOB (X,XX,XXX),'MAIL ATT'MSGCLASS=F,CLASS=D,

// REGION=M

//**********************************************************************************************

//PS030 EXEC PGM=IEBGENER

//SYSPRINT DD SYSOUT=*

//SYSIN DD DUMMY

//SYSOUT DD SYSOUT=*

//SYSUT2 DD SYSOUT=A,DEST=SMTPTEST

//SYSUT1 DD DISP=SHR,DSN=EMAIL.HDR.INFO

// DD DISP=SHR,DSN=EMAIL.ATTATCH.INFO

// DD DISP=SHR,DSN=EMAIL.FILE.CONTENT

//********** END OF JOB**************************************

In the above code we can observe that there are three files. Let us see what information these files contains

Contents of File1: EMAIL.HDR.INFO

This file contains the following code

HELLO mailserver

MAIL FROM: <abc@xyz.com>

RCPT TO: <abc@xyz.com>

RCPT TO: <def@xyz.com>

DATA

FROM: abc@xyz.com

TO: jackson@xyz.com,robert@xyz.com,

bouton@xyz.com

SUBJECT: Status Report

MIME-VERSION: 1.0

Content-Type: MULTIPART/MIXED; BOUNDARY="MIME"

--MIME

CONTENT-TYPE: TEXT/PLAIN; CHARSET=US-ASCII

CONTENT-TRANSFER-ENCODING: 7BIT

Hello All,


Please find the status report attached


Thanks & Regards,

Mainframe Team.

Contents of file1 EMAIL.HDR.INFO

(Click on the image for better view)
(Click on the image for better view)

Contents of File1 EMAIL.HDR.INFO continued

(Click on the image for better view)
(Click on the image for better view)

Contents of file2 EMAIL.ATTACH.INFO

This file contains the following code, which tells that what is the file name that should go an attachment along with the mail.

--MIME

CONTENT-TYPE:TEXT/PLAIN; NAME=STATUS-REPORT.CSV

CONTENT-DISPOSITION: ATTACHMENT; FILENAME=STATUS-REPORT.CSV

Contents of file2 EMAIL.ATTATCH.INFO

(Click on the image for better view)
(Click on the image for better view)

Contents of File3: EMAIL.FILE.CONTENT

This file contains the data which will be sent as an attachment(stuts-report.csv file).

(Click on the image for better view)
(Click on the image for better view)

In the above file we can observe that fields are separated with comma. For to send the content of any file as a .csv(comma separated values) attachment the fields in the file should be separated with comma.

Want to know how to send a simple email from mainframe (with out attachments) click on the below link

send an email from mainframe


Please leave a comment if you have any questions.


More by this Author


Comments 4 comments

Umesh 4 years ago

I tried above steps..it works correct when file length is 80 bytes...when I tried content file length around 2000 bytes, it didn't work...the other 2 files length including SYSUT2 were also 2000 bytes.


Nagesh Kajjam 3 years ago

I tried but it's not working for me. Any idea ?


yaswanthk profile image

yaswanthk 3 years ago Author

Hi Nagesh,

Have you checked the record format of your files ? . Record format of all the files you coded at SYSUT1 should be same.

Please share the JCL, which you tried for sending an email. and also the run details of your job.

Thank you


Francis Guarnes 6 months ago

Hi Nagesh,

Limitation - The maximum rec length allowed for attachment is 998. The only way to send your 2000 byte records is via FTP or SFTP. Thank you.

Francis

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working