Page 1 of 1

send email with an attachment from the mainframe

Posted: Sat Oct 12, 2024 4:08 pm
by Arun Rajput
Hi,

Can anyone help on How to send email with an attachment from the mainframe?

Thanks,
 

Re: send email with an attachment from the mainframe

Posted: Sat Oct 12, 2024 6:54 pm
by zum13
Hello.

I've sent emails from jobs in the past, but not attachments. Emailing involves the "SMTPNOTE" command, the TSO "TRANSMIT" command or the SMTP external reader. From the documentation, none of these appear to have been explicitly set up to handle attachments: https://www.ibm.com/docs/en/zos/3.1.0?t ... pplication

This is not to say that it is not possible. There is an example shown here: https://www.ibm.com/docs/en/zos/3.1.0?t ... tpiebgener . The file that is being sent is constructed using commands from the SMTP protocol (HELO, MAIL FROM:, RCPT TO:, etc), the idea being that if you can write something that produces the same kind of thing, the SMTP daemon will be able to send it.

In order to send an attachment, you would need something that would not only write the necessary SMTP commands but the MIME protocol (which is what allows attachments to happen). There are various command line utilities around that will do this on other systems (e.g. mailx, mutt). There are also extensions within Python and other scripting languages that will let you do it (for example, see https://keentolearn.medium.com/automati ... a00fa98b92). The problem is that they while they may be runnable under USS, they may not necessarily understand the environment they are running in and they may try to bypass the SMTP daemon as a result. However, if one of these utilities can be made to write it's work to a file complete with SMTP protocol commands then it can be sent using z/OS's facilities as per the IEBGENER example.

One thing you would need to be wary of is ensuring that the file you are sending is not EBCDIC if the user/system you are sending to cannot handle it.

Sorry I cannot be of more help than that. Hopefully there's someone on here who's actually done it in practice.

Re: send email with an attachment from the mainframe

Posted: Tue Oct 15, 2024 10:28 pm
by Robert Sample
Find and study RFC 5321, which is the Internet standard way to use SMTP to send mail.  Sending attachments usually requires experimentation as the format is EXTREMELY picky and one wrong character may cause the attachment to not send.  Also, your site must have enabled the SMTP writer.  I recommend starting with a simple email (no attachment), getting it to work, then expanding to a text attachment, then finally to using MIME attachments.

Re: send email with an attachment from the mainframe

Posted: Wed Oct 16, 2024 6:43 pm
by myoggradio
We have a Java program that works with Java 8 and is based on Oracle's mail.jar.
Here is the JCL to run the program.
If required, I will send you the *.jar files.
Please note that it no longer works with Java 11.
If you want, you can receive the source code or the jar file by email. 

Code: Select all

//SENDMAIL JOB (430430137),'D42313',MSGCLASS=Q,MSGLEVEL=(1,1), 
// NOTIFY=&SYSUID,CLASS=S,REGION=0M                    
//JAVA EXEC PROC=JVMPRC80,LOGLVL='+T',                         
// JAVACLS='pack.Main'                                         
//STDENV DD *                                                  
. /vwb/sysprog/profile8                                        
CLASSPATH=$CLASSPATH:/vwb/sysprog/java/zosMail                 
CLASSPATH=$CLASSPATH:/vwb/sysprog/javalib/mail.jar             
//*                                                            
//PARM DD *                                                    
SUBJECT=IPLINFO - VBP1 + VBP2 - Job SENDMAIL                   
FROM=christian@gibtnich.de                             
TO=christian@gibtnich.de                           
TXTDD=APPENDIX1                                                  
TXTDD=APPENDIX2                                                  
ENCODING=ISO-8859-1                                            
/*                                                             
//APPENDIX1 DD DISP=SHR,DSN=D42313.SYSPRINT.IPLINFO.VBP1         
//APPENDIX2 DD DISP=SHR,DSN=D42313.SYSPRINT.IPLINFO.VBP2         
//TEXT DD *                                                    
Attached is the current IPL info                                    
/                                                             
*//* Valid parameters are:                                          
//* SUBJECT                                                          
//* Subject of the email                                               
//* FROM                                                              
//* Sender                                                        
//* TO                                                             
//* Recipient                                                      
//* Header card can be specified multiple times                     
//* CC                                                               
//* Carbon Copy                                                     
//* Header card can be specified multiple times                     
//* BCC                                                              
//* Blind Carbon Copy                                               
//* Header card can be specified multiple times                     
//* ATT                                                              
//* Name of an Open MVS file that is sent as an attachment in binary form 
//* e.g.: /u/D42313/OpenJPA.pdf                                     
//* Header card can be specified multiple times                     
//* DD                                                               
//* Name of a Jes file that is sent as an attachment in binary form;     
//* maximum 8 characters.                                              
//* Header card can be specified multiple times                     
//* TXTDD                                                            
//* Name of a Jes text file that is sent as an attachment;       
//* maximum 8 characters.                                              
//* Header card can be specified multiple times                     
//* ENCODING                                                         
//* Character set of the email and the text attachment                      
//* MAXCHARACTERS                                                       
//* Maximum number of characters in the email (without attachment)          
//* SMTPSERVER                                                       
//* TCP/IP address of the mail server; only specify as an exception        
//* SMTPPORT                                                         
//* TCP/IP port of the mail server; only specify as an exception           

Re: send email with an attachment from the mainframe

Posted: Wed Oct 16, 2024 9:08 pm
by myoggradio
Habe den Quelltext mal angehängt

Re: send email with an attachment from the mainframe

Posted: Fri Oct 18, 2024 4:03 pm
by enrico-sorichetti
did Your organization consider XMITIP

https://groups.io/g/xmitip

Re: send email with an attachment from the mainframe

Posted: Mon Oct 21, 2024 1:03 pm
by Arun Rajput
Thank you everyone for the pointers. I am new to it all, I am working on it. Will get back you how it works out. 

Re: send email with an attachment from the mainframe

Posted: Mon Oct 21, 2024 1:04 pm
by Arun Rajput
enrico-sorichettidid Your organization consider XMITIP

https://groups.io/g/xmitip
I am not sure about it, I shall ask around about it.

Re: send email with an attachment from the mainframe

Posted: Mon Oct 21, 2024 1:15 pm
by Anuj Dhawan
@myoggradio - I have added the code tags to your post. Kindly review them to ensure they are correct.

Re: send email with an attachment from the mainframe

Posted: Tue Oct 22, 2024 5:28 pm
by myoggradio
Hallo Anuj,
Danke für Deine Mühe die Tags zu setzen.
Aber eigentlich ist Alles eine zusammenhängende JCL.
Gruß Christian

Re: send email with an attachment from the mainframe

Posted: Tue Oct 22, 2024 8:20 pm
by Anuj Dhawan
Hi Christian,

Kindly confirm if this meets your expectations, and please feel free to provide any further feedback.

Regards,

Re: send email with an attachment from the mainframe

Posted: Tue Oct 22, 2024 9:03 pm
by myoggradio
Super, so ist es gut

Re: send email with an attachment from the mainframe

Posted: Tue Oct 29, 2024 10:40 am
by Arun Rajput
Thank you everyone for your help. We are working on our process to make it work, based on the inputs.