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 . . . . . . . . > email@example.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:
|*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((firstname.lastname@example.org)) + 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((email@example.com *PRI) + (firstname.lastname@example.org *PRI) + (email@example.com *CC) + (firstname.lastname@example.org *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) ENDMSFWait 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.