Jan 1 ’07

Sending HTML Email From Your Mainframe

by Editor in z/Journal

Did you know you can send HTML-formatted email from your mainframe? I’m always looking for ways to make our mainframe look sexier and more versatile to our management team to keep them from retiring the platform.

Our organization recently experienced some rather severe performance issues with our Enterprise Resource Planning (ERP) system. The mainframe wasn’t the cause of the problem; the main symptom was high-DB2 utilization on the mainframe. While troubleshooting this problem, our middle-management team asked if they could receive some type of automatic notification when the mainframe was experiencing high-CPU utilization.

I already had in place a custom CPU performance-monitoring system that runs an RMF post-processor CPU report every 30 minutes. A Rexx program parses the RMF report and sends the CPU percent-busy numbers to a Web-based graphing system. I modified this Rexx script to send an HTML-based email when the CPU surpassed 90 percent busy (see Figure 1).

This article describes how to create and send HTML-based email via a mainframe batch job, including some techniques I used to create the automated high-CPU email alert system used in my shop. The main focus is the mechanics of sending HTML-formatted email via z/OS-based mainframes.

Getting Started

Before you can begin sending HTML-based emails via your mainframe, you must make sure the Simple Mail Transfer Protocol (SMTP) gateway process works on your system. A simple way to do this is to try sending an e-mail from the mainframe. The JCL shown in Figure 2 can be used to perform this test. Just modify the highlighted components in the JCL in Figure 2 to match your environment. Notice the SYSUT2 DD statement. The SMTP server that runs on your mainframe interfaces with Job Entry Subsystem (JES).

If the email isn’t sent, check to see if the SMTP started task is running on your system. The standard name for this task is SMTP. If all else fails, read through the “Mail Servers” chapter of the z/OS V1Rx CS: IP Configuration Guide and make the customizations shown there. The link for this manual is specified in the References section of this article.

Anatomy of an HTML Email Message

To send HTML-formatted email, you must use the Multi-purpose Internet Mail Extensions (MIME) standard. This extends email support to include non-text attachments and text in character sets other than ASCII. MIME also provides a standard way to send HTML-formatted email.

The batch job in Figure 3 generated the email shown in Figure 1. Three PDS members are concatenated under the SYSUT1 DD statement; each contains parts of the entire HTML-formatted email message. This setup makes it easier to modify the dynamic portion of the email via our automated performance-monitoring system. When our performance-monitoring system detects that the CPU utilization has been at 90 percent or greater for a 30-minute interval, it will replace the EMAILP2 member with the appropriate text, and then submit the batch job shown in Figure 3.

SMTP Statements

The first section of the email message is contained in the EMAILP1 member. The EMAILP1 member is shown in Figure 4. The statement numbers shown in Figure 4 are for illustration purposes only. Statements 1 through 7 are used to tell SMTP about the email message. These seven statements tell SMTP who the message is from, who the message is to, and the subject of the email. In statement 1, APCTSAPT is the Network Job Entry (NJE) name of the MVS node we’re running this batch job on. But I can put anything I want in place of APCTSAPT and the job still works fine.

Statements 9 and 10 tell SMTP we’ll be using MIME to generate an email that may contain both text and HTML-formatted data.

HTML Statements

The HTML statements start at line 10 in Figure 4. Statement 25 defines a table that has a width of 100 percent. This table is used to set the background color. You also could set the background color using the <BODY> statement, but some email programs delete the <BODY> statement, so setting the color using a table is safer.

In statement 29, another table is created within the first table. This second table has a width of 600 pixels. Many email users view their email using the email program’s preview pane. You should make your HTML emails thin enough to look good within the preview pane. Experiment with different widths, viewing your email message both with and without the preview pane.

Statements 30 through 32 show you how to include an image in your HTML-formatted email message. Statement 30 starts a new table row. Statement 31 identifies the image to be included, and statement 32 ends the table row.

The EMAILP2 member is updated to reflect the date, time, and actual CPU busy percentage when our automated performance monitoring system detects a high-CPU utilization condition. This portion of the message was split out from the rest of the email message to make it easier for the performance monitoring system to format the message (see Figure 5).

EMAILP3 member, shown in Figure 6, contains the remainder of the HTML-coded email message.

Conclusion

The sample HTML email message illustrated in this article is a bare bones-type of email. You should take this sample and experiment. Add your own graphics, throw in a few links, and change the colors. It’s possible to create your email message using an HTML editor, such as Dreamweaver and FrontPage, but you’ll probably have to manually massage the generated HTML code to work properly with your email system.

There’s also a flaw in the z/OS SMTP service. Notice that in Figure 4 the name of the email sender is specified. You can actually put any name you want in this field and it will pass right through the SMTP server as coded. Using this flaw to send emails posing as others isn’t a great idea. Remember, System Management Facility (SMF) captures everything, so exploiting this flaw can be traced back to you.

You also must ensure the member (or data set) containing your HTML and SMTP statements isn’t numbered. If you have numbers in columns 73 through 80, it can wreak havoc. Use the ISPF UNNUM command to eliminate these sequence numbers. Z

References