• 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
    ARCAD Software

    DevSecOps & Peer Review – The Power of Automation

    In today’s fast-paced development environments, security can no longer be an afterthought. This session will explore how DevSecOps brings security into every phase of the DevOps lifecycle—early, consistently, and effectively.

    In this session, you’ll discover:

    • What DevSecOps is and why it matters?
    • Learn how to formalize your security concerns into a repeatable process
    • Discover the power of automation through pull requests, approval workflows, segregation of duties, peer review, and more—ensuring your data and production environments are protected without slowing down delivery.

    Whether you’re just getting started or looking to enhance your practices, this session will provide actionable insights to strengthen your security posture through automation and team alignment to bring consistency to the process.

    Watch Now!

    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

  • Power Systems Grows Nicely In Q3, Looks To Grow For All 2025, Too
  • Beta Of MCP Server Opens Up IBM i For Agentic AI
  • Sundry IBM i And Power Stack Announcements For Your Consideration
  • Please Take The IBM i Marketplace Survey
  • IBM i PTF Guide, Volume 27, Number 43
  • IBM Pulls The Curtain Back A Smidge On Project Bob
  • IBM Just Killed Merlin. Here’s Why
  • Guru: Playing Sounds From An RPG Program
  • A Bit More Insight Into IBM’s “Spyre” AI Accelerator For Power
  • IBM i PTF Guide, Volume 27, Number 42

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