Common Questions About Sending Email from IBM i Programs

Article ID: 58510

Q: How do I send an email message from my IBM i program?
Q: You said SNDDST is old school. How else can I send an email?
Q: I need to send an email with more than one attachment. Is that possible?
Q: If I don't want to use the IBM SMTP server, do I have to use Java to send mail?

These are examples of the questions I receive about sending email from IBM i. This is just the tip of the iceberg. On average, I receive two questions every day about email. It's one of the most asked about items!

In this article, I point you to articles and free utilities that you can use to solve your email problems.

IBM provides the Send Distribution (SNDDST) command with i. However, this command is a relic of days gone by. It's a little tricky to set up to work with today's Internet-oriented email, but it's not too bad. The big trouble with SNDDST is its limitations! You are very limited in the amount of formatting you can do to messages. Attachments can come only from the archaic /QDLS portion of the IFS, and you can attach only one file. The syntax of the SNDDST command is ugly because it contains a lot of parameters that aren't used in today's email. My recommendation? Don't use SNDDST.

Free Email Software

One of the reasons it's easy to say "don't use SNDDST" is that there are so many better alternatives available. There are quite a few free email tools available that you can download and install. If they're free, simpler, and more versatile than SNDDST, why still use SNDDST today?

Here's a list of email tools you can get for free:

  • MIME & Mail (MMAIL) from Easy400.

    This is arguably the most complete of the free email tools, as well as the most popular. It's actively developed as an open-source project. It contains tools for sending mail, receiving mail, and even converting spooled files to PDF format so they can be sent.

    The one disadvantage of MMAIL that I'm aware of is that it uses the QtmmSendMail API from IBM, which forces you to run the IBM i SMTP server. In my opinion, the IBM SMTP server performs poorly and is difficult to troubleshoot problems with.

    That's a relatively small disadvantage, however. MMAIL is well worth a try!

  • Send Mail (SNDM) by Uzaemon (real name is Hideyuki Yahagi).

    Implemented as a single CL command, SNDM allows a text message with up to five attachments to be sent. It's simple but far more powerful and versatile than SNDDST. On the same site (but in a separate download) there's also a RCVM program for receiving mail, as well as tools for creating .ZIP files and .PDF files.

    This tool is much better than SNDDST but is not quite as versatile as MMAIL. It doesn't allow HTML mail to be sent and doesn't allow more than five attachments. On the plus side, however, it doesn't require the IBM i SMTP server. You can use your company's SMTP server (usually provided as part of Exchange, Domino, or Unix mail servers.)

  • MAIL command from Jean-Paul Lamontre.

    Like SNDM, this MAIL tool is provided as a CL command. However, unlike SNDM, it's capable of sending HTML-formatted messages and allows up to 100 attachments.

    Like MMAIL, this tool is based on IBM's QtmmSendMail() API and therefore requires the SMTP server to run on the i. It's not quite as versatile as MMAIL but is simpler to use.

  • SNDEMAIL by David Leland.

    This tool was published in the September 1998 issue of System iNEWS magazine and has been enormously popular with our readers. Unfortunately, this tool is very limited. It doesn't handle attachments properly and makes assumptions about the character set that you're using. It also uses the QtmmSendMail API and so has the limitations of that API. With the more versatile email options we have today, I find it hard to recommend this one.

    However, I know people who have been using this tool for years and swear by it!

  • RPGMAIL by Aaron Bartell.

    RPGMail is a set of RPG wrappers around Sun's JavaMail API. When you are using RPGMail, you are actually calling routines written in Java. One of the advantages to this method is that the JavaMail API is versatile and well written. Unlike most of the options listed here, it does not require the QtmmSendmail API and doesn't require that you run the SMTP server on your i.

    The disadvantage is that it uses Java. That means that troubleshooting is difficult unless you have at least a little Java experience, as error messages are generally provided in Java format. Because of the Java, it is slower than the other options (Java simply cannot match native program speeds) and requires the extra memory and overhead that Java is famous for.

  • SNDMAIL from Alex Nubla.

    This tool was recommended by one of the participants in the System iNetwork forums. However, I haven't tried it myself, and therefore I'm not able to give any commentary on it.

My Own Email Articles & Tools

All these free tools have limitations of one type or another. Personally, I prefer not to be limited! By writing my own email tools, I can make them work the way I want them to work. I can overcome any limitation I run into.

I also find it useful to understand how email works under the covers, even if I use someone else's tool. Understanding email makes it easier to troubleshoot and easier to administer.

Of course, if you don't feel that way, you don't have to understand! Just download one of the tools above and you're all ready to go. If you want to learn how email works and put together your own tools (possibly by using fragments of my code), you're welcome to. I've written the following articles about how email works and how to write your own tools for email:

  • Send E-Mail Messages with SMTP

    This article discusses how to write your own TCP/IP software to take a message (already in email format) and send it over a network. With this tool, you can send email messages to another SMTP server so that you don't need to have SMTP running on i. Even if you want to keep the SMTP server running on i, you can use the techniques discussed in this article to get better diagnostics about why email delivery is failing.

    Using the tools I provide in the article, you can put together your own email tools that are much easier to write than if you had to call the QtmmSendMail() API. The interface also makes it easy to convert existing QtmmSendMail() programs to use my SMTP tooling, and therefore you'll be able to send email to network SMTP servers.

  • E-Mail Message Bodies

    This article describes the internal format of an email message. It shows many examples of how to format an email message and send it with QtmmSendMail API (with minor changes, it could use the SMTPR4 utility from the SMTP article, above.)

    This article explains how to build HTML formatted email, how to build messages that contain both HTML and text versions of the content, how to embed pictures into an HTML email, and how to send attachments. It comes with complete sample code.

  • Sending E-Mail from QShell and PASE Scripts

    QShell and PASE both make it easy to write data to stream files in the IFS, and therefore they are great candidates for writing email software. This article demonstrates how to build email messages from the QShell/PASE environments instead of the traditional IBM i environment.

  • Base64 Is Built In to IBM i

    Base64 is a scheme used to protect binary data as it's sent through email. Earlier this year, I discovered that I didn't have to use my own Base64 tools, because IBM has the Apache Base64 routines provided with the OS.

    This article shows you how to use those routines and demonstrates using them to create an email message with a Base64-encoded attachment.

Conclusion

A lot of free email tools are available for IBM i. Hopefully this article has shed some light on what tools are available and why you'd want to use them. After you try a few of the email tools, I'm sure you'll find what you need to make your next email-related project a big success!

ProVIP Sponsors

ProVIP Sponsors