Sending an Email from JCL with attachment

In this Mainframe Forum - You can post your queries on JCL, OS/390 JCL, MVS JCL, z/OS JCL, JES2 & JES3

Moderators: Frank Yaeger, DikDude, Moderator Group

User avatar
muraligaru1
Moderator
Posts: 43
Joined: Sat Nov 11, 2006 7:03 pm

Sending an Email from JCL with attachment

Post by muraligaru1 » Tue Oct 07, 2008 4:22 pm

Hi,

In my project, one of the requirement is to send the mail to a group of people. attach a sequential file to that mail.

I have the JCL to send a simple mail.... i dont know, how to send an attachment with it. Please provide the jcl for this.


Thanks for help.

User avatar
Kalicharan
Moderator
Posts: 31
Joined: Wed Feb 08, 2006 1:51 pm

Post by Kalicharan » Wed Oct 08, 2008 10:34 am

This can be done using the below SAS program.

//MAILJCLX JOB (DEVLD,TEST),'MAILJCLX TEST',CLASS=X,MSGCLASS=X,NOTIFY=&SYSUID
//STEP0 EXEC SAS
//REPORT1 DD DSN=DVAN.MFDATASET.TEST,DISP=SHR
//SYSIN DD *
%LET MAILFILE = %SYSFUNC(PATHNAME(REPORT1));

DATA _NULL_;

CALL SYMPUT(?FDATE?, LEFT(PUT(?&SYSDATE?D-1,WORDDATE.)));

FILENAME LNOTE EMAIL TO=(?mail-id1? ?mail-id2?)
CC=(?ccmail-id1?)
BCC=(?bccmail-id1?)
SUBJECT =?TEST MAIL - &SYSDATE?
ATTACH =(?&MAILFILE? EXTENSION='TXT' TYPE='TEXT/PLAIN' NAME=?MFREPORT?);
DATA _NULL_;
FILE LNOTE ;
PUT
?This will be the content of the mail?;
PUT ' ';
RUN;

Here REPORT1 DSN will be send as attachment with the name MFREPORT.TXT in plain text format
to the mail-ids specified in ?FILENAME LNOTE EMAIL? with the subject TEST MAIL ? 03OCT08"

User avatar
muraligaru1
Moderator
Posts: 43
Joined: Sat Nov 11, 2006 7:03 pm

sending mail from JCL IEBGENER

Post by muraligaru1 » Thu Oct 09, 2008 4:55 pm

Thanks Kalicharan.

Currently i am using IEBGENER to send a mail.

Is it possible to send an attachment using IEBGENER?
Please provide the JCL for the same.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

sending an email from jcl with IEBGENER with attachment.

Post by Natarajan » Sat Oct 11, 2008 2:16 pm

Try following code.

Code: Select all

//SENDMAIL JOB (XXX,YYY),                                            
//             'MAIL FILE ',                                            
//             MSGCLASS=T,                                              
//             CLASS=S                                                                            
//*                                                                     
//STEP01   EXEC PGM=IEBGENER                                            
//SYSIN    DD  DUMMY                                                    
//SYSPRINT DD  SYSOUT=*                                                 
//SYSUT2   DD  SYSOUT=(M,SMTP)                                          
//SYSUT1   DD  DISP=SHR,                                                
//                  DSN=DEV.XXXX.TEST.FILE
//              DD DISP=SHR,     
//                  DSN=DEV.XXXX.TEST.FILE2(0) 
//*      

Contents of the file DEV.XXXX.TEST.FILE :
helo JOBTRAC
MAIL FROM:<Natarajan@gmail.com>
rcpt to:<Natarajan@gmail.com>
data
FROM: xxxxx
TO: Natarajan@gmail.com
SUBJECT: test mail
Mime-Version: 1.0
Content-Type: text/plain; name="XYZZ.txt"
Content-Disposition: attachment; filename="XYZZ.txt"

DEV.XXXX.TEST.FILE2(0) is the file which should be send as attachment
Both files DCB?s should match.


Let me know, if you face any problems with this JCL

tavisha.sareen
Member
Posts: 6
Joined: Sat Jan 24, 2009 2:43 am

Post by tavisha.sareen » Sat Jan 24, 2009 2:46 am

I want to send multiple attachments in a single email through IEBGENER.Please suggest what needs to be done.

User avatar
snatcher
Member
Posts: 2
Joined: Sun Feb 08, 2009 8:00 pm
Location: Bangalore

Post by snatcher » Sun Feb 08, 2009 8:40 pm

tavisha.sareen wrote:I want to send multiple attachments in a single email through IEBGENER.Please suggest what needs to be done.

Code: Select all

//PLNMMX05 EXEC PGM=IEBGENER                                  
//SYSPRINT DD SYSOUT=*                                        
//SYSIN    DD DUMMY                                            
//SYSOUT   DD SYSOUT=*                                        
//SYSUDUMP DD SYSOUT=D                                        
//SYSUT2   DD SYSOUT=&#40;B,SMTP&#41;                                  
//SYSUT1   DD DSN=JSULNC.MAIL.HELLO,DISP=SHR                
//              DD DSN=JSULNC.MAIL.ATTACH1,DISP=SHR              
//            DD DSN=JSULNC.REPORT.TEXT1,DISP=SHR  
//         DD DSN=JSULNC.MAIL.ATTACH2,DISP=SHR 
//            DD DSN=JSULNC.REPORT.TEXT2,DISP=SHR  


Contents of JSULNC.MAIL.ATTACH1 is:

Code: Select all

--MIME                                  
CONTENT-TYPE&#58; TEXT/PLAIN;NAME=RECY.TXT  
CONTENT-TRANSFER-ENCODING&#58; 7BIT          
CONTENT-DISPOSITION&#58; ATTACHMENT;        
FILENAME=JSULNC.BHAVANI.HELLO;          
                                        


Contents of JSULNC.MAIL.ATTACH2 is:

Code: Select all

 
MIME-VERSION&#58; 1.0                                
CONTENT-TYPE&#58; MULTIPART/MIXED;BOUNDARY="MIME"    
                                                
--MIME                                          
CONTENT-TYPE&#58; TEXT/PLAIN; CHARSET=US-ASCII      
CONTENT-TRANSFER-ENCODING&#58; 7BIT                  
                                                
HI ,          
                                    
    PLEASE FIND THE ATTACHED REPORTS. 

REGARDS 
SUPPORT TEAM 
                                                
--MIME                                          
CONTENT-TYPE&#58; TEXT/PLAIN;NAME=DIFF.TXT          
CONTENT-TRANSFER-ENCODING&#58; 7BIT                  
CONTENT-DISPOSITION&#58; ATTACHMENT;                
FILENAME=JSULNC.REPORT.TEXT2;            



Note:DCB of JSULNC.MAIL.ATTACH1, JSULNC.MAIL.ATTACH2, JSULNC.REPORT.TEXT2 and JSULNC.REPORT.TEXT1 should be the same. New line breaks is a must.
Cheers!
Snatcher

tavisha.sareen
Member
Posts: 6
Joined: Sat Jan 24, 2009 2:43 am

Post by tavisha.sareen » Sat Feb 21, 2009 3:39 am

Where do we need to put the email addresses to which the email needs to be sent and also let me know the content of file JSULNC.MAIL.HELLO.
Thanks

User avatar
snatcher
Member
Posts: 2
Joined: Sun Feb 08, 2009 8:00 pm
Location: Bangalore

Post by snatcher » Sat Feb 21, 2009 1:16 pm

Hi There,

I missed the contents of the JSULNC.SMTP.HELO, it is as follows:

Code: Select all

HELO FELTG
MAIL FROM&#58; <XXXXXXXXXXXXXX@YYYYYYY.CO.UK>  
RCPT TO&#58; <yyyyyyyyyyyyyyyy@YYYYYYY.CO.UK>  
RCPT TO&#58; <ZZZZZZZZZZZZZZ@YYYYYYY.CO.UK>  
DATA                                               
FROM&#58; <XXXXXXXXXXXXXX@YYYYYYY.CO.UK>  
TO&#58; <yyyyyyyyyyyyyyyy@YYYYYYY.CO.UK>  
CC&#58; <ZZZZZZZZZZZZZZ@YYYYYYY.CO.UK>  
SUBJECT&#58; Report files attached 

Where FELTG is for handshaking, You should ask your mainframe admin for the handshake which you should use for successfull delivery of mail from your mainframe server.
Cheers!
Snatcher

tavisha.sareen
Member
Posts: 6
Joined: Sat Jan 24, 2009 2:43 am

Post by tavisha.sareen » Mon Feb 23, 2009 9:14 am

I am trying to do the same way u suggested but then m still getting a single attachment in the mail.Also I have csv files to attch in the email.
Please suggest..

Thanks

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Email with attachmet

Post by subasu » Mon Apr 13, 2009 1:11 pm

Natarajan,

You JCL worked for an attachment. However, when I try to put in a body in the email like some written message, the attachment stops working. I am trying to put in the text/message between the SUBJECT and MINE-Version: 1.0. Please let me know if I am doing something wrong or suggest the correct format.

Thanks.
Subhadeep Basu.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Mon Apr 13, 2009 8:37 pm

Hi Subhadeep,

Change the content of the file DEV.XXXX.TEST.FILE :

helo JOBTRAC
MAIL FROM:<Natarajan@gmail.com>
rcpt to:<Natarajan@gmail.com>
data
FROM: xxxxx
TO: Natarajan@gmail.com
SUBJECT: test mail
Mime-Version: 1.0
Content-Type: MULTIPART/MIXED;"SIMPLE BOUNDARY"
Hi,

How r you

Regards,
Natajan
--SIMPLE BOUNDARY
Content-Type: text/plain; name="XYZZ.txt"
Content-Disposition: attachment; filename="XYZZ.txt"


Let me know, if you still facing the issue.
Natarajan
Chennai

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Tue Apr 14, 2009 9:19 am

Natarajan,

I am still facing the same issue, the mail is delivered, but there is no attachment, instead i get the following in the mail.
***********************************************************
Hi Nitin,
This is the test for body of the email
Thanks,
Subhadeep Basu
--SIMPLE BOUNDARY
Content-Type: text/plain; name="confirm.txt"
Content-Disposition: attachment; filename="confirm.txt"
PEON.CP000000.PCCS.FFB.CCS0P0000000000010000000000
************************************************************
The data"PEON.CP000000.PCCS.FFB.CCS0P0000000000010000000000" should come as an attachment.
-- Please let me know if you have a remedy for the same.

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

Post by Natarajan » Tue Apr 14, 2009 3:10 pm

Look like boundary is not working.. let me check and get back to you.
Natarajan
Chennai

User avatar
Natarajan
Moderator
Posts: 537
Joined: Fri Oct 10, 2008 12:57 pm
Location: chennai
Contact:

SMTP send attachment

Post by Natarajan » Tue Apr 14, 2009 3:49 pm

Hi,

please check below code.

Code: Select all

helo JOBTRAC 
MAIL FROM&#58;<Natarajan@gmail.com> 
rcpt to&#58;<Natarajan@gmail.com> 
data 
FROM&#58; xxxxx 
TO&#58; Natarajan@gmail.com 
SUBJECT&#58; test mail 
Mime-Version&#58; 1.0 
Content-Type&#58; MULTIPART/MIXED;boundary="mainframegurukul"

--mainframegurukul
Content-type&#58; text/plain

This is the body of the message.
--mainframegurukul
Content-Type&#58; text/plain; name="XYZZ.txt" 
Content-Disposition&#58; attachment; filename="XYZZ.txt" 


Make sure you have another PS file in SYSUT1, which contain following
--mainframegurukul--

OR

add this string at the end of the attachment data.
Natarajan
Chennai

subasu
Member
Posts: 12
Joined: Tue Mar 24, 2009 1:12 pm

Post by subasu » Tue Apr 14, 2009 3:54 pm

Natarajan,

The following one worked.
===============================================
HELO SYSA
MAIL FROM:<XXXX@XXXX.COM>
RCPT TO:<XXXXX@XXXXX.COM>
DATA
FROM: <XXXXXXX@XXXX.COM>
TO: <XXXXXXX@XXXX.COM>
SUBJECT: Test Mail for attachment and body
MIME-Version: 1.0
Content-Type: MULTIPART/MIXED;
boundary="SIMPLE BOUNDARY"
--SIMPLE BOUNDARY

Hi Nitin,
This is the test for body of the email
Thanks,
Subhadeep Basu

--SIMPLE BOUNDARY
Content-Type: text/plain; name="confirm.txt"
Content-Disposition: attachment; filename="confirm.txt"
===============================================

Thanks for your help to get me started!!!

Post Reply

FREE TUTORIALS

Tutorials
Free tutorials from mainframegurukul
  • JCL Tutorial
    Covers all important JCL concepts.
  • Cobol Tutorial
    This tutorials covers all Cobol Topics from STRING to COMP-3.
  • DB2 Tutorial
    DB2 Tutorial focuses on DB2 COBOL Programming.
  • SORT Tutorial
    This Tutorial covers all important aspects of DFSORT with examples
  • CICS Tutorial
    This CICS tutorial covers CICS concepts and CICS Basics, CICS COBOL Programming.
Interview
Mainframe Interview questions



Other References
Mainframe Tools and others