how to send an attatchment with email



JES, JES2, JCL utilities, IDCAMS, Compile & Run JCLs, PROCs etc...

how to send an attatchment with email

Postby Surabhi » Fri Mar 11, 2016 3:07 am

Hi all,

I did go through a number of pages and examples and also tried alot of examples for sending an attacthment, but no luck.
My requirement is i want to send a mail with attacthment.
below is the jcl i have used:-
//STEP01 EXEC PGM=IEBGENER
//SYSIN DD DUMMY
//SYSPRINT DD SYSOUT=*
//SYSUT2 DD SYSOUT=(B,SMTP)
//SYSUT1 DD DSN=abc.report,
// DISP=SHR
// DD DSN=abc.mail.file,
// DISP=SHR
/*

abc.report
*****************************
HELO name
MAIL FROM:<email-id>
RCPT TO:<email.id>
DATA
TO: email-id
FROM: email-id
SUBJECT: TEST MAIL
MIME-VERSION: 1.0
CONTENT-TYPE: TEXT/PLAIN
CONTENT-DISPOSITION: ATTACHMENT;
FILENAME=abc.mail.file.txt

abc.mail.file
************************************
This is the input file which contains information and I want this to be attacthed in the mail in .txt format

The abc.report and abc.mail.file are the fixed block PS files with 300 lrecl.

The issue i am facing is the job is going down with MAXCC 0 i.e no errors or abends, but i am not able to receive any mail nor the attacthment.
Could you please help me out with this.

Thank You in advance.
Surabhi
 
Posts: 43
Joined: Thu Sep 10, 2015 7:51 pm
Has thanked: 3 times
Been thanked: 0 time

Re: how to send an attatchment with email

 

Re: how to send an attatchment with email

Postby Aki88 » Fri Mar 11, 2016 10:15 am

Hello,

To start with, check whether you have the requisite accesses to trigger SMTP (in general convention, there are site-restrictions - almost always).
Next up, look at the SMTP logs for the time-stamp at which the mail request was initiated. In case of delivery failure, you should see a 'EZA5477E', if SMTP DEBUG is 'on', then you definitely should look at the SYSDEBUG output; if there is an error at SMTP, the log does give you enough pointers to crack the problem.

Lastly, revisit the JCL- depending on what you find from the above checkpoints.

Here is a link for the z/OS Communications Server: IP Messages Volume 1 (EZA) manual, it'll help you in understanding the EZA messages generated for the shared job (if it did trigger the SMTP).

Hth.
Aki88
 
Posts: 338
Joined: Tue Jan 28, 2014 1:52 pm
Has thanked: 32 times
Been thanked: 31 times

Re: how to send an attatchment with email

Postby Robert Sample » Fri Mar 11, 2016 10:35 am

This is one of those cases where you REALLY need to consult with your site support group. SMTP is NOT a required component of TCP/IP, so it may -- or may not -- even be working at your site. If it is working, SYSOUT=(B,SMTP) assumes that your site is using SYSOUT class B for SMTP traffic (which is something that must be confirmed AT YOUR SITE), and that SMTP is the name of the started task for SMTP (again, something that varies from site to site).

Furthermore, my experience has been that SMTP is VERY sensitive to the format being used for attachments -- below is one that I've used in the past to send email with attachments via SMTP. The blank lines are NOT optional. The member EMAILAT contains the trailing period on a line by itself that is REQUIRED by SMTP and that I do not see in your JCL. You will also note that the site I ran this job on used SYSOUT class 9, not B, for SMTP. If you are going to be sending 300-byte fixed length records then everything in SYSUT1 will need to be 300-byte fixed-length records, which means you will NOT be able to use DD * and send the email.

//MAILPROC EXEC PGM=IEBGENER
//SYSABEND DD   SYSOUT=*
//SYSTOTAL DD   SYSOUT=*
//SYSLIST  DD   SYSOUT=*
//SYSPRINT DD   SYSOUT=*
//SYSUT2   DD   SYSOUT=(9,SMTP)
//SYSIN    DD   DUMMY
//*
//SYSUT1   DD   *
HELO MAINFRAME.XXX.COM
MAIL FROM: <MAINFRAME@XXX.COM>
RCPT TO: <ROBERT.SAMPLE@XXX.COM>
DATA
FROM:     MAINFRAME@XXX.COM
TO:       ROBERT.SAMPLE@XXX.COM
DATE:     JANUARY 24, 2016
SUBJECT:  TEST ATTACHMENT
MIME-VERSION: 1.0
CONTENT-TYPE: MULTIPART/MIXED; BOUNDARY="SIMPLE BOUNDARY"
--SIMPLE BOUNDARY
CONTENT-TYPE: TEXT/PLAIN
CONTENT-DISPOSITION: ATTACHMENT; FILENAME=EMAILATT.TXT

//         DD   DISP=SHR,DSN=TTSSRS0.JCL.CNTL(EMAILATT)
//         DD   *
--SIMPLE BOUNDARY
CONTENT-TYPE: TEXT/PLAIN
CONTENT-DISPOSITION: ATTACHMENT; FILENAME=EMAILTST.TXT

//         DD   DISP=SHR,DSN=TTSSRS0.JCL.CNTL(EMAILTST)
//         DD   *
--SIMPLE BOUNDARY--
//         DD   DISP=SHR,DSN=TTSSRS0.JCL.CNTL(EMAILAT)
//

These users thanked the author Robert Sample for the post:
Terry Heinze (Tue Mar 15, 2016 7:21 pm)
Robert Sample
Global moderator
 
Posts: 3202
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 196 times

Re: how to send an attatchment with email

Postby Terry Heinze » Tue Mar 15, 2016 7:21 pm

Your example proved extremely helpful, Robert.
.... Terry
Terry Heinze
 
Posts: 178
Joined: Wed Dec 04, 2013 11:08 pm
Location: Richfield, MN, USA
Has thanked: 10 times
Been thanked: 11 times

Re: how to send an attatchment with email

Postby Robert Sample » Tue Mar 15, 2016 8:55 pm

I'm glad it helped, Terry. That JCL came about after a number of hours of research and experimentation. The applications programmers wanted to send attachments, and I was tasked with finding out how to get attachments sent. Some variations exist, such as putting everything into PDS members to allow record lengths other than 80 (anything up to 998 will work), but the base SMTP code has been working for me for at least 6 or 7 years now.
Robert Sample
Global moderator
 
Posts: 3202
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 196 times

Re: how to send an attatchment with email

Postby Robert Sample » Tue Mar 15, 2016 11:42 pm

Surabhi: upon re-reading your post, it is not clear if you have ever sent an email from the mainframe using SMTP before or not. If not, you need to start with a simple text message -- something like
HELO MAINFRAME.XXX.COM
MAIL FROM: <MAINFRAME@XXX.COM>
RCPT TO: <ROBERT.SAMPLE@XXX.COM>
DATA
FROM:     MAINFRAME@XXX.COM
TO:       ROBERT.SAMPLE@XXX.COM
DATE:     March 15, 2016
SUBJECT:  TEST MESSAGE
test
.
 
If this goes to your email client, then you know you've got the connection correct. If you copy this to (B,SMTP) and you don't get the email reasonably quickly (I'd allow 30 minutes or so -- it's usually seconds but that will depend on the site and the SMTP traffic of the site), then you'll need to work with your site support group as something basic isn't right. That could include line numbers in 73 - 80 (SMTP does not understand line numbers), wrong SYSOUT class, wrong started task name, mainframe pointing to wrong mail server, mainframe not pointing to a mail server at all, or various other set up issues. If you don't understand the format listed here, you'll need to find RFC2821 and RFC2822 about SMTP to learn more -- the HELO, MAIL FROM:, MAIL TO: and DATA lines have a particular format to follow. And, as I said earlier, the final period is not optional for SMTP -- some sites automatically put it in for you but many do not.

Once you're getting emails from the mainframe, then you can focus on attachments.
Robert Sample
Global moderator
 
Posts: 3202
Joined: Sat Dec 19, 2009 8:32 pm
Location: East Dubuque, Illinois
Has thanked: 1 time
Been thanked: 196 times


Return to JCL

 


  • Related topics
    Replies
    Views
    Last post