• 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
    Manta Technologies

    The Leader in IBM i Education!
    Need training on anything i?
    Manta is all you need.

    130 courses and competency exams on:
    · IBM i operations
    · System Management and Security
    · IBM i Programming Tools
    · Programming in RPG, COBOL, CL, Java
    · Web Development

    SQL, DB2, QueryProduct features:
    · Runs in every popular browser
    · Available 24/7/365
    · Free Student Reference Guides
    · Free Student Administration
    · Concurrent User License
    · Built-In IBM i Simulator

    You can download our 200-page catalog and take sample sessions at MantaTech.com

    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

Content archive

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

Recent Posts

  • IBM Unveils Manzan, A New Open Source Event Monitor For IBM i
  • Say Goodbye To Downtime: Update Your Database Without Taking Your Business Offline
  • i-Rays Brings Observability To IBM i Performance Problems
  • Another Non-TR “Technology Refresh” Happens With IBM i TR6
  • IBM i PTF Guide, Volume 27, Number 18
  • Will The Turbulent Economy Downdraft IBM Systems Or Lift It?
  • How IBM Improved The Database With IBM i 7.6
  • Rocket Celebrates 35th Anniversary As Private Equity Owner Ponders Sale
  • 50 Acres And A Humanoid Robot With An AI Avatar
  • IBM i PTF Guide, Volume 27, Number 17

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