Page 2 of 2

Re: Sending Email with attachments via REXX

PostPosted: Thu Aug 20, 2009 11:38 pm
by arshadhrashid
Thanks for your help.
I will update you later.

Re: Sending Email with attachments via REXX

PostPosted: Thu Sep 10, 2009 6:20 pm
by Anuj Dhawan
Though I'm quite late to party and with a usuless contibution to this thread but does this thread really belongs to the part of the forum known as "Suggestions & Feedback"? :?

Re: Sending Email with attachments via REXX

PostPosted: Fri Sep 11, 2009 1:10 am
by dick scherrer
Hi Anuj,

Probably not. . . :)

d

Re: Sending Email with attachments via REXX

PostPosted: Fri Oct 06, 2017 1:40 am
by kcjpq200
I hunted everywhere for a solution to this, but figured it out. I hope this helps.
It will send a plain text dataset as a plain text attachment via Rexx & S/MIME

/* Send dataset as an attachment via SMTP MIME */
recipient = 'someuser@somewhere.com'              
jes_node = 'jes_node_name_to_get_to_smtp'        
subj = 'Subject Line Here'                        
msg_body = 'Message Body Here'                    
full_dsdata_name = 'MAINFRAME_DATA_SET_NAME_HERE'
file_att = full_dsdata_name                      

SMTP.1  = "HELO "jes_node                                              
SMTP.2  = "MAIL FROM:<somehost@someplace.com>"                        
SMTP.3  = "RCPT TO:<"recipient">"                                      
SMTP.4  = "DATA"                                                      
SMTP.5  = "Date: "date(w) date(m) day year time()                      
SMTP.6  = "From: HOST <somehost@someplace.com>"                        
SMTP.7  = "To:   <"recipient">"                                        
SMTP.8  = "Subject: "subj                                              
SMTP.9  = "MIME-VERSION: 1.0"                                          
SMTP.10 = "CONTENT-TYPE: MULTIPART/MIXED; BOUNDARY=""SIMPLE BOUNDARY"""
SMTP.11 = "--SIMPLE BOUNDARY"                                          
SMTP.12 = "CONTENT-TYPE: TEXT/PLAIN"                                  
SMTP.13 = "                    "                                      
SMTP.14 = "Do not reply to this email"                                
SMTP.15 = "                    "                                      
SMTP.16 = msg_body                                                    
SMTP.17 = "--SIMPLE BOUNDARY"                                          
SMTP.18 = "CONTENT-DISPOSITION: ATTACHMENT; FILENAME="file_att".txt"  
SMTP.19 = "CONTENT-TYPE: TEXT/PLAIN"                                  
SMTP.20 = "                    "                                      
  Address "OPSDYNAM"                                                  
    "allocate fi(input) dataset('"full_dsdata_name"') shr"            
  say "File" full_dsdata_name "allocated."                            
                                                                     
   Address "TSO"                                                      
    "execio * diskr input (finis"                                    
/* Next line must equal the last hardcoded SMTP.XX number, adding 1 */
n = 21   /* This portion and below DO are needed to get this to work - SMTP.n is the line read from the file */                      
     do while queued() > 0                                            
       parse pull mychain                                            
       SMTP.n = mychain                                              
       n = n + 1                                                      
     end                                                              
SMTP.n = "."                                                          
n = n + 1                                                            
SMTP.n = "QUIT"                                                      
                                                                     
Address "OPSDYNAM"                                                    
  "free f(input)"                                                    

  Address "TSO"                                                  
  "alloc f(smtpout) sysout(a) writer(cssmtp)"    /* SMTP or CSSMTP */                 
    say "CSSMTP writer Allocation Return Code:" rc                
    say "Allocated" SMTPOUT                                      
                                                                 
  Address "TSO"                                                  
  "execio * diskw smtpout (STEM SMTP. FINIS"                      
    say "EXECIO of SMTPOUT TO SMTP WRITER RETURN CODE:" rc        
                                                                 
  Address "OPSDYNAM"                                              
  "free f(smtpout)"                                              
      if rc = 0 then do                                          
        say "File" full_dsdata_name "sent to SMTP for attachment",
            "processing."                                        
      end                                                        
/* End of send email attachment routine */