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

    Do you need area code information?
    Do you need ZIP Code information?
    Do you need ZIP+4 information?
    Do you need city name information?
    Do you need county information?
    Do you need a nearest dealer locator system?

    We can HELP! We have affordable AS/400 software and data to do all of the above. Whether you need a simple city name retrieval system or a sophisticated CASS postal coding system, we have it for you!

    The ZIP/CITY system is based on 5-digit ZIP Codes. You can retrieve city names, state names, county names, area codes, time zones, latitude, longitude, and more just by knowing the ZIP Code. We supply information on all the latest area code changes. A nearest dealer locator function is also included. ZIP/CITY includes software, data, monthly updates, and unlimited support. The cost is $495 per year.

    PER/ZIP4 is a sophisticated CASS certified postal coding system for assigning ZIP Codes, ZIP+4, carrier route, and delivery point codes. PER/ZIP4 also provides county names and FIPS codes. PER/ZIP4 can be used interactively, in batch, and with callable programs. PER/ZIP4 includes software, data, monthly updates, and unlimited support. The cost is $3,900 for the first year, and $1,950 for renewal.

    Just call us and we’ll arrange for 30 days FREE use of either ZIP/CITY or PER/ZIP4.

    WorksRight Software, Inc.
    Phone: 601-856-8337
    Fax: 601-856-9432
    Email: software@worksright.com
    Website: www.worksright.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

  • To Comfort The Afflicted And Afflict The Comfortable
  • How FalconStor Is Reinventing Itself, And Why IBM Noticed
  • Guru: When Procedure Driven RPG Really Works
  • Vendors Fill In The Gaps With IBM’s New MFA Solution
  • IBM i PTF Guide, Volume 27, Number 27
  • With Power11, Power Systems “Go To Eleven”
  • With Subscription Price, IBM i P20 And P30 Tiers Get Bigger Bundles
  • Izzi Buys CNX, Eyes Valence Port To System Z
  • IBM i Shops “Attacking” Security Concerns, Study Shows
  • IBM i PTF Guide, Volume 27, Number 26

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