Pages

Tuesday, December 3, 2013

Email IFS files

send ibmi as400 email sndsmtpemm

The subject matter of this post compliments the previous post Zipping files in the IFS, which describes how to copy a file to the IFS and zip it in preparation for sending it via email.

Until recently it was not possible to email a file from the IFS without using a third party tool or an API. There is the command SNDDST that I have used to send emails from an IBM i (AS400) with the contents of files or files located in the QDLS file system as attachments. But it cannot access the IFS.

A new command SNDSMTPEMM has been introduced, via PTF, to IBM i 6.1 and 7.1 that allows you to email a file from the IFS as an attachment.

The first screen of parameters is fairly obvious what they are for. The exception, perhaps, being the "Type" which I have selected the email address to be the primary receipient.

                          Send SMTP E-mail (SNDSMTPEMM)

 Type choices, press Enter.

 RECIPIENT:
   E-mail address . . . . . . . . > my-address@email.com                     
                                                                             
                                                                             
                                                    
   Type . . . . . . . . . . . . .   *PRI          *PRI, *CC, *BCC
                + for more values  
 SUBJECT  . . . . . . . . . . . . > Example of using SNDSMTPEMM                
                                    
 NOTE . . . . . . . . . . . . . . > This area is for the email body text     
                                                                             
                                                                              
                                                                             
                                                                             
                                                                             
                                                                    
                                                                        More...

The second screen of parameters is where I enter the details for the attachment. In this example I am going to send the file I zipped in Zipping files in the IFS. The "Content type" is *ZIP as the file being attached is a zipped file, I will describe below the valid values for this parameter below. The "TYPE" is *BIN as the zipped file is a binary rather than a text, *TXT, file. The other parameters I leave with their defaults.

                          Send SMTP E-mail (SNDSMTPEMM)

 Type choices, press Enter.

 ATTACHMENT:                       
   File name  . . . . . . . . . . > MyFolder/extract.zip                     
                                                                             
                                                                             
                                                                             
                                                                             
                                                                             
                                                                    
   Content type . . . . . . . . . > *ZIP                                        

   TYPE . . . . . . . . . . . . .   *BIN          *BIN, *TXT
                + for more values  
 Character set:
   Character set name . . . . . .   *UTF8                                    
                                    
   Character set CCSID  . . . . .   *DFT          1-65533, *DFT
                                                                        More...

The only parameter on the third screen can be ignored.


                          Send SMTP E-mail (SNDSMTPEMM)

 Type choices, press Enter.

 Password . . . . . . . . . . . .                                            
                                                                             
         


                                                                         Bottom

The valid "Content type" values is extensive and covers a lot of the file types I would send from an IBM i, and some I probably would not:

Content type Description
*OCTET Octet-stream
*PLAIN Plain text
*HTML XML
*RTF rtf
*PDF Adobe pdf
*VISIO Visio
*ZIP Zip files
*POST Postscript
*L123 Lotus-1-2-3
*FREE Lotus Freelance
*WORDPRO Lotus Wordpro
*WORD Microsoft Word
*POWERPT Microsoft PowerPoint
*EXCEL Microsoft Excel
*AC3 Audio ac3
*MP3 Audio mp3
*WAV Audio wav
*GIF Image gif
*BMP Image bmp
*JPEG Image jpeg
*PNG Image png
*MPEG Video mpeg
*MSG Message (rfc822)
*OGG Codec compressed mulitmedia file
character-value A valid IANA registered MIME type.
Up to 60 characters can be specified.

If I was to send the unzipped file then I would change the "Content type" to *PLAIN, and the "TYPE" to *TXT:

  SNDSMTPEMM RCP((my-address@email.com)) +
               SUBJECT('Unzipped extract') +
               NOTE('Attached is the unzipped extract file') +
               ATTACH(('MyFolder/extract.csv' *PLAIN *TXT))

If you wanted to send the email to multiple people you would need to use the TYPE parameter like this:

  SNDSMTPEMM RCP((jane@email.com *PRI) +
                 (mary@email.com *PRI) +
                 (emma@email.com *CC) +
                 (my-address@email.com *BCC)) + 
               SUBJECT('Unzipped extract')
               NOTE('Attached is the unzipped extract file')
               ATTACH(('MyFolder/extract.csv' *PLAIN *TXT))
  • *PRI = primary recpients. In the above example that is Jane and Mary.
  • *CC = copy. I have copied Emma.
  • *BCC = blind copy. I have sent myself a blind copy for my records.

One thing I did find when using this command is that when the file I was sending became a certain size the email received would no longer have the attachment, but I would get several emails containing, only what I can describe as, garbage.

The helpful person at IBM Support explained to be that I had to change the message split size for POP (= Post Office Protocol). Then stop the SMTP sever, stop and start the Mail Server Framework, and start SMTP server. These are the commands I ran:

   CHGPOPA MSGSPLIT(*NOMAX)
   ENDTCPSVR SERVER(*SMTP)
   ENDMSF
  Wait a few seconds
   STRMSF
   STRTCPSVR SERVER(*SMTP)

After waiting a few seconds for the Mail Server Framework and SMTP server to complete starting I could use the STRSMTPEMM command again.

At the time this post was written there is no Help for this command. Therefore, I have included IBM's technical document and their README file in the links below.

43 comments:

  1. Just tried it and it works perfectly - very easy - THANKS

    ReplyDelete
  2. When I worked closer with spam filtering, I blocked all emails with a zipped attachment less than 120 kbytes in size as they almost always contained viruses. My point is that files less than 10 Mbytes in size should not be zipped. My current mail service unzips zipped attachments and scans them for viruses so it's not as much as an issue, but I still don't like to see zipped attachments in email.

    ReplyDelete
    Replies
    1. "... files less than 10 Mbytes in size should not be zipped." I know of a couple of exceptions: first, digital certificates. They are very small and often have to be emailed, but Microsoft in their infinite wisdom blocks them as potentially harmful, so they must be given a different file extension somehow to get past MS Outlook. Zipping them is the easiest way to do this.

      Second, zipping is a convenient way to bundle several files that must be sent as a group. It's not just used to reduce email size. For example, the "new" MS Office formats (.docx, .xlsx, etc.) are all just zipped bundles of files in disguise, and are probably the most common email attachments sent.

      Delete
  3. Simon. I just solve a problem with your explanation..

    Thanks a lot

    ReplyDelete
  4. This post is about native IBM i/AS400 commands used to send email.

    I am aware of numerous 3rd party tools from various vendors that also do this. But as they do not come on all IBM i servers as part of the initial software I have not mentioned them.

    ReplyDelete
  5. It's alright as far as it goes, but the functionality is still limited:
    Can you send an email with high priority?
    Can you ensure you get a receipt whe the addressee opens it?
    Is there a record of emails sent?
    Is it possible to format the text in the email? SNDDST allows formatting, but I have not been able to do it with SNDSMTPEMM.
    Why has it taken IBM such a long time to get even this bit of functionality?

    ReplyDelete
  6. Get garbage in my email file when use Sndsmptemm and send a .csv file that was created by a program and used cpytoimpf to upload to folder. Works fine if the file was created using query.

    Any suggestions?

    ReplyDelete
    Replies
    1. The fourth paragraph from the bottom might be describing what you are experiencing.

      Try changing those settings and see if that solves your problem.

      Delete
    2. Hi Simon,

      I too was having the same issue as Sandy. I ran the commands as you have identified in the fourth paragraph above. Still having the same issue. I can see the file I have saved to the IFS in .csv format is correct (doing a copy/save of the .csv file to my desktop) but the SNDSMTPEMM command continues to send garbage.

      Any suggestions?

      Elaina

      Delete
    3. I would try CHGPOPA as I have described, and see if that fixes your problem.

      Delete
  7. Hi,
    i tried to use this command but getting an error- "Integrated File System File Not Found.
    Send E-mail Failed."

    also kindly let me know if this command can be used for attaching more than one .txt files.

    thnks in advance.

    ReplyDelete
  8. I cannot say why you are getting an error message when trying to use the IFS. It could be any number of things. It is always best to give the error message id when errors are encountered.

    You can send more than one attachment. Put a "+" in the 'Attachment' field to expand that part of the display to add more.

    ReplyDelete
  9. Hi Simon,

    The link has changed for the technical document.
    http://www-01.ibm.com/support/docview.wss?uid=nas8N1011153

    Thank you for writing your articles!

    ReplyDelete
  10. Great article! I cannot email a .csv using SNDSMTPEMM. If anyone has emailed a .csv using this command could you share your command parameters (i.e. content type, type, CS name, CS ccsid)? Thanks.

    ReplyDelete
    Replies
    1. I create the csv using the following command.
      CPYTOIMPF FROMFILE(&UtilLib/&Extract) +
      TOSTMF(&TgtFil) +
      STMFCCSID(*PCASCII) STMFAUT(*INDIR) +
      RCDDLM(*CRLF) DTAFMT(*DLM) +
      STRDLM(*DBLQUOTE) STRESCCHR(*STRDLM) +
      RMVBLANK(*BOTH) ADDCOLNAM(*SYS)
      and then email using
      SNDSMTPEMM RCP((&EmailAdr *PRI)) +
      SUBJECT(&Subject) +
      NOTE(&Text) +
      ATTACH((&AttFil *PLAIN *TXT))
      Not sure if it's required but, for &TgtFile I use \ as the separator and for &AttFil, I used
      /. eg. \Folder\File.csv and /Folder/File.csv

      I plan to experiment and see if one style of formatting will work for both commands.

      Delete
  11. Hi Anonymous,

    This is my statement when sending a csv file. This forum did not allow me to insert HTML tags so I changed the angle brackets to hyphens.

    SNDSMTPEMM RCP((glenn.gundermann@company_name.com *PRI))
    SUBJECT('This is the subject line')
    NOTE('-p-This message has been sent automatically.-/p--p-Please do not reply back to this email. Should you have any question or concern, please contact the Help Desk Support Team at helpdesk@company_name.com.-/p--p-Thank you.-/p--p-Attached:-/p--p-file_name.csv-/p-')
    ATTACH(('/root_folder/sub_folder/file_name.csv' *PLAIN *TXT))
    CONTENT(*HTML)

    ReplyDelete
  12. Hi

    If multiple email id's are given in SNDSMTPEMM using a parameter, it does not work as the parameter is in CHAR type and it automatically uses quotes when passed as a parameter.

    Any ideas how to resolve it?

    Thanks

    ReplyDelete
    Replies
    1. See this post here on how to do what you are talking about

      Delete
  13. I'm pretty new to writing CLP. I'm doing some testing with sending emails using a CLP I've written. I've entered the following:

    SNDSMTPEMM RCP ((MYEMAIL@EMAIL.COM *PRI))
    SUBJECT('TEST')
    ATTACH(/FOR_EXCEL/VTOPENCLAIMS.CSV))

    I get an message "parameter SUBJECT required"

    So I tried adding:

    PARM KWD(SUBJECT) TPYE(*CHAR) LEN(40)

    Which gives me a separate error of: "command parm not allowed in this setting"

    Any hints?

    ReplyDelete
    Replies
    1. You need the continuation marker (+) at the end of the first two lines. eg.

      SNDSMTPEMM RCP ((MYEMAIL@EMAIL.COM *PRI)) +
      SUBJECT('TEST') +
      ATTACH(/FOR_EXCEL/VTOPENCLAIMS.CSV))

      Delete
  14. I used your routine to copy a DB2 file to the IFS and email it as a .CSV file. It worked great.

    ReplyDelete
  15. Hello,
    I am getting the following after issuing the SNDSMTPEMM command. Can anyone help?

    Pointer not set for location referenced.
    Pointer not set for location referenced.
    Application error. MCH3601 unmonitored by QTMSCSEAPI at statement
    0000000001, instruction X'0000'.
    Send E-mail Failed.

    ReplyDelete
    Replies
    1. I usually see that message where I have used a variable that is in the PARM list (at the top of the program), and I have omitted to pass it.

      Delete
    2. I issued it on the command line for testing. I want to see it work first. This is the command (email addresses changed for privacy). Attachment was created with CPYTOIMPF, which downloads just fine with FTP on PC command line.

      SNDSMTPEMM RCP((CONTACT1@NAVY.MIL) (CONTACT2@NAVY.MIL *CC) (CONTACT3@NAVY.MIL *CC)) SUBJECT('Emailing boscextract_new_yyyymmdd.TXT') NOTE('XXX: Sending work order data for import to Maximo. Record count: 19') ATTACH(('/NOLA2MAX/boscextract_new_yyyymmdd.TXT' *PLAIN *TXT))

      Delete
    3. I am not sure what you want me to say. That looks valid to me.

      You will have to check your job log to see what other else is amiss.

      Delete
    4. Message . . . . : Application error. MCH3601 unmonitored by QTMSCSEAPI at statement 0000000001, instruction X'0000'.

      Cause . . . . . : The application ended abnormally because an exception occurred and was not handled. The name of the program to which the unhandled exception is sent is QTMSCSEAPI QTMSCSESEC crashed__15QTMSSecureEmailFv. The program was stopped at the high-level language statement number(s) 0000000001 at the time the message was sent. If more than one statement number is shown, the program is an optimized ILE program. Optimization does not allow a single statement number to be determined. If *N is shown as a value, it means the real value was not available.

      Delete
    5. What release of IBM i is this happening on?
      7.1?

      Delete
    6. Did you find the answer here to the pointer error? we just updated to 7.3 and am now getting the error intermittently but too often.

      Delete
    7. From what I could find for 7.1 this is an known error. There is a PTF for it, for 7.1.

      Christa: I wold contact IBM support, report this issue to them, and ask if there is a PTF for it.

      Delete
    8. We are also having intermittent issues after going to 7.3 from 7.1. Will see if IBM has a PTF.

      Delete
    9. I've had issues using multiple *CC. It appears SNDSMTPEMM only likes 1.

      Delete
    10. You must be doing something wrong as I just sent an email using SNDSMTPEMM to 1 primary and 3 CC, and they were all delivered.

      Delete
    11. Check if your company's email system blocks certain email addresses.

      Delete
    12. Appears our Power9 can't send email outside the company anymore. I agree with you - we are doing something wrong.

      Delete
  16. Is there a way, to mark email with priority *HIGH?

    ReplyDelete
    Replies
    1. There is no high priority. All emails are sent with equal importance.

      Delete
  17. This may be off topic, but does the recipient have to be user on iSeries?

    ReplyDelete
    Replies
    1. When testing I have been able to send emails from the IBM i to my GMail address.

      Delete
  18. Simon, good article. At one site, we’ve been unable to send and when chatting with IBM support, they said SNDSMTPEMM is not supported as standalone email capability, but must be used with an external server, windows, Linux, cloud, office365 to send outside IBMi via a RELAY. I was shocked as I thought in past, IBMi was a mail server. There is no “cook book” for smtp setup that describes these scenarios. So SNDSMTPEMM is great for sending PDFs etc.but only IF YOU HAVE IT SETUP! Any resources for that you could recommend?

    ReplyDelete

To prevent "comment spam" all comments are moderated.
Learn about this website's comments policy here.

Some people have reported that they cannot post a comment using certain computers and browsers. If this is you feel free to use the Contact Form to send me the comment and I will post it for you, please include the title of the post so I know which one to post the comment to.