• The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
Menu
  • The Four Hundred
  • Subscribe
  • Media Kit
  • Contributors
  • About Us
  • Contact
  • Sending E-Mail from RPG

    May 12, 2004 Hey, David

    [The code for this article is available for download.]

    A few years ago you wrote an article about sending e-mail using the QzmfCrtMailMsg API. I used your code at my last job to send e-mail from RPG programs. I told my new boss I could set it up so that we could send e-mail from our RPG programs, but I don’t have the magazine with that article. Is that article available online, and is the QzmfCrtMailMsg still the way to go?

    –Frank

     

    Back in 1998, QzmfCrtMailMsg was a good option for RPG programmers, but there are better options today. One of those options is the JavaMail API. The advantages of the JavaMail API are price, reliability, cross-platform compatibility, and simplicity. The disadvantages are performance and no vendor support.

    Writing a Java program that uses the JavaMail API isn’t too difficult, once you get past some of the nuances of creating and running Java programs on the iSeries. I wrote a sample Mailer Java program you can use to get started. You can call that sample program from an RPG IV program, like the sample MailerDemo RPG IV program. Comments in the source for the sample programs describe how to compile and run these programs on the iSeries.

    The following summary describes the methods found in the Mailer class.

    • getSession creates a JavaMail Session object for the URL defined in a mail.smtp.host property, using an optional JavaMail Authenticator object. The authenticator is created if mail.user and mail.password properties exists.

    • sendSimpleMail (to, from, subject, message) creates and sends a JavaMail message with no attachments.

    • sendMultiPartMail (to, from, subject, message, bodyParts) creates and sends a JavaMail message with multiple parts that can have attachments.

    Properties used by the Mailer class can be defined in a Mailer.properties file or by setting system properties. The sample mailer JUnit test allows you to test the Mailer from a Java program. For more information on running JUnit, see “JUnit Automates Java Testing.”

    The Mailer starts by opening a session to an SMTP server. You specify the URL for the SMTP server in a mail.smtp.host property. If you supply a user and password, via the mail.user and mail.password properties, the program uses them to authenticate to the SMTP server. After creating a session, a message is created and sent using the session.

    The RPG program will run only on V5R1 or later releases that have support for direct Java calls. The RPG program starts by creating four string objects. Those four strings contain the “from” and the “to” addresses, along with the subject and message. The next thing the RPG program does is to call the Mailer’s sendSimpleMail method to send a message.

    Mixing RPG and Java to send mail may seem complex, but this solution is actually much simpler than the convoluted Mail Server Framework APIs.

    –David

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    Tags:

    Sponsored by
    DRV Tech

    Get More Out of Your IBM i

    With soaring costs, operational data is more critical than ever. IBM shops need faster, easier ways to distribute IBM applications-based data to users more efficiently, no matter where they are.

    The Problem:

    For Users, IBM Data Can Be Difficult to Get To

    IBM Applications generate reports as spooled files, originally designed to be printed. Often those reports are packed together with so much data it makes them difficult to read. Add to that hardcopy is a pain to distribute. User-friendly formats like Excel and PDF are better, offering sorting, searching, and easy portability but getting IBM reports into these formats can be tricky without the right tools.

    The Solution:

    IBM i Reports can easily be converted to easy to read and share formats like Excel and PDF and Delivered by Email

    Converting IBM i, iSeries, and AS400 reports into Excel and PDF is now a lot easier with SpoolFlex software by DRV Tech.  If you or your users are still doing this manually, think how much time is wasted dragging and reformatting to make a report readable. How much time would be saved if they were automatically formatted correctly and delivered to one or multiple recipients.

    SpoolFlex converts spooled files to Excel and PDF, automatically emailing them, and saving copies to network shared folders. SpoolFlex converts complex reports to Excel, removing unwanted headers, splitting large reports out for individual recipients, and delivering to users whether they are at the office or working from home.

    Watch our 2-minute video and see DRV’s powerful SpoolFlex software can solve your file conversion challenges.

    Watch Video

    DRV Tech

    www.drvtech.com

    866.378.3366

    Share this:

    • Reddit
    • Facebook
    • LinkedIn
    • Twitter
    • Email

    PFSweb Launches E-Commerce App for iSeries Shops i5 Announcements Loaded with Software, Previews

    Leave a Reply Cancel reply

Volume 4, Number 16 -- May 12, 2004
THIS ISSUE
SPONSORED BY:

Advanced Systems Concepts
Guild Companies
WorksRight Sofware
*noMAX
Client Server Development

Table of Contents

  • Tomcat 5 and DB2 for iSeries
  • Writing Control Break Programs
  • Changing Prototypes and Dual Prototyping
  • Sending E-Mail from RPG
  • OS/400 Alert: i5, or iHype?

Content archive

  • The Four Hundred
  • Four Hundred Stuff
  • Four Hundred Guru

Recent Posts

  • The Power11 Transistor Count Discrepancies Explained – Sort Of
  • Is Your IBM i HA/DR Actually Tested – Or Just Installed?
  • Big Blue Delivers IBM i Customer Requests In ACS Update
  • New DbToo SDK Hooks RPG And Db2 For i To External Services
  • IBM i PTF Guide, Volume 27, Number 33
  • Tool Aims To Streamline Git Integration For Old School IBM i Devs
  • IBM To Add Full System Replication And FlashCopy To PowerHA
  • Guru: Decoding Base64 ASCII
  • The Price Tweaking Continues For Power Systems
  • IBM i PTF Guide, Volume 27, Numbers 31 And 32

Subscribe

To get news from IT Jungle sent to your inbox every week, subscribe to our newsletter.

Pages

  • About Us
  • Contact
  • Contributors
  • Four Hundred Monitor
  • IBM i PTF Guide
  • Media Kit
  • Subscribe

Search

Copyright © 2025 IT Jungle