You've Got Mail!

Before closing and sending the e-mail, we must attach the PDF file containing the invoice data. This PDF could've been generated from an OS/400 spooled file. (Note: If you don't have a utility to translate spooled files into PDF files, the Easy400 documentation includes information on three ways to do this and details limitations and prerequisites of each. There's even a limited-function spooled-file-to- PDF conversion tool inside the MIME & Mail utility.) For simplicity, we assumed the PDF was already generated and we must simply attach it to the temporary e-mail file. The second parameter provided the PDF file's name. In our example program, we accepted this value as an input parameter. The last three parameters have static values to indicate the type of file we're attaching (ContType = 'application/pdf'), whether we want to attach the file as binary (BinFlag = 'Y') and whether it should be embedded or attached (ImbAtt=2 for attachment).

C                 CallP     MimeImbAtt(TempFile : InvPDFFile :
C                        ;  ContType : BinFlag : ImbAtt)

Next, we called the MimeClose procedure, which adds the appropriate termination characters to the e-mail file:

C                   CallP     MimeClose(TempFile)

At last our temporary e-mail file has the necessary content, so we're ready to send it. The SendMail procedure is a simplifying wrapper for the QtmmSendMail system API. Note that we passed the sender and receiver information again. While this may seem redundant, the information is required by the API to do the sending even though the same information is already formatted inside the e-mail's contents.

C       Eval      Error = SendMail(TempFile :
C                  FromEmail : ToAddrArr : ToDistArr)

The SendMail procedure returns a CPF message ID in the Error field if an error occurs. Otherwise the Error field is blank.

All Done

And that's it. We have intentionally kept our example program simple. In real life, for example, we would've made this a subprocedure in a service program and wouldn't have wanted to open and close the customer file for each invoice. There may also be better ways of getting the PDF file name, but our intention was to illustrate the simplicity of the e-mail creation and sending process with attachments from an RPG program using the free utility programs and documentation from the IBM* Easy400 Web site.

The MIME & Mail utility allows you to do much more, including validate e-mail address formats and attach everything from source members to database files as well as image, audio and video files. The interactive utility we used to create the template file in the first step also includes the capability to generate and send an e-mail dynamically, from a 5250 screen, complete with such attachments.

Give it a Try

Easy400 does it again-the MIME & Mail Utility provides an easier way to create and send e-mails from RPG applications. The Web site even helps you configure your system for SMTP and provides instruction on how to make all this work even if your iSeries* server isn't your outgoing e-mail server. Give it a try. You may be surprised at what you can do from RPG.

The complete source for our sample program is available here. And when you decide to try the MIME & Mail utility for yourself, read more about it here.

Jon Paris is a technical editor with IBM Systems Magazine and co-owner of Partner400.

Susan Gantner is a technical editor with IBM Systems Magazine and co-owner of Partner400.

comments powered by Disqus



2017 Solutions Edition

A Comprehensive Online Buyer's Guide to Solutions, Services and Education.

A PPP Monitor Utility

Here's a program developed to programmatically obtain the status of a PPP connection

IBM Systems Magazine Subscribe Box Read Now Link Subscribe Now Link iPad App Google Play Store
IBMi News Sign Up Today! Past News Letters