Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Intercepting and Logging Email\
via Z_SENDMAIL

Table of Contents

1. Abstract

2. Introduction

3. How Interception and Logging Works

4. Email Handling Categories

5. The Tables

Intercepting and Logging Email

Table of Contents

 

Table of Contents

1. 

...

Abstract

To view an abstract of this document, click here.

2. 

...

Introduction

The majority of SMTP (internet) email sent from the MIT R/3 systems is sent via the custom function module Z_SENDMAIL. This function has been modified from its original state to enable programmers to instruct Z_SENDMAIL to intercept and/or log outgoing email that it processes.

Two custom tables, ZEHCAT and ZEMCTRL are used to control both interception and logging of email, and the log is written to a third custom table, ZEMLOG.

...

Logging of email, while useful for debugging purposes, particularly for intermittent problems or problems that occur in the R/3 production system, is intended to be used solely for short-term debugging purposes and should only be enabled when attempting to track down a problem. Logging is not intended, nor should it be used, as an audit trail of messages sent.

3.  How Interception and Logging

WorksEach call to Z_SENDMAIL is associated with an email handling category taken either from parameter P_HNCAT or, if this parameter is not included in the function call, from table ZEMCTRL (see below for details on this distinction). The handling category is referenced in control table ZEHCAT, which contains the following instructions for processing the Z_SENDMAIL call based on the assigned handling category:

  1. Whether to log the call to Z_SENDMAIL.
  2. Whether to intercept the email message, and if so, whether to:
    1. Discard the message.
    2. Redirect the message to alternate "To" and "Cc" addresses.
      (The alternate addresses are provided by ZEHCAT).
    3. Write the message to a UNIX file.
      (The UNIX path suffixed after "/usr/bridges/<system>/saptmp/" is supplied by ZEHCAT).
    4. Write the message to an SAP printer spool file.
      (The printer name and spool settings are provided by ZEHCAT).

...

If a program that calls Z_SENDMAIL pre-dates the intercepting and logging modifications, such programs do not require modification simply to add a handling category to the function call. Although it is intended that every existing call to Z_SENDMAIL will eventually be modified to pass an explicit email handling category, programmers have the option of using table ZEMCTRL to map such programs to the appropriate handling category.
To map a calling program to a handling category, an entry is made in table ZEMCTRL with the calling program name as it appears in SY-CPROG and the desired email handling category. This method allows only a single handling category per program, and so is not suitable for programs that require more than one handling category. Also, this method does not require a transport to R/3 environments other than the environment in use.ZEMCTRLField NameData ElementData TypeLengthDescriptionMANDTMANDTCLNT3ClientPROGPROGRAMMCHAR40Calling

ZEMCTRL

Field Name

Data Element

Data Type

Length

Description

 

MANDT

MANDT

CLNT

3

Client

 

PROG

PROGRAMM

CHAR

40

Calling program name
(SY-CPROG)

...

 

HNCATZ

HNCAT

CHAR

2

Associated email handling category


The categoryThe table of current email handling category assignments can be found here.


When a chain of programs is called, care should be taken in determining the value for field PROG, the calling program name as it appears in SY-CPROG. It is the first program within a chain of calls that is the calling program.

4.  Email Handling

...

Categories

Each email handling category is a unique, two-letter assignment designated for use by particular ABAP programs for their exclusive use. Handling categories are assigned based on the type of email and the class of recipient to receive the email, and so a program not explicitly assigned to a particular handling category may not use that category.

The handling category (either passed as parameter P_HNCAT or retrieved from table ZEMCTRL) is referenced in table ZEHCAT, and the following instructions for processing the Z_SENDMAIL call are retrieved:

...

How the imposed handling category is then processed depends on the contents of table ZEHCAT. If there are no entries in table ZEHCAT for the current R/3 system, all email sent via Z_SENDMAIL will be delivered normally, that is, will neither be intercepted nor logged. Table ZEHCAT in the production system, for instance, should typically contain no entries to allow for normal email delivery. If table ZEHCAT contains only the entries shown below for the <space><space> and ++ handling categories, all email sent via Z_SENDMAIL will be intercepted and discarded. Upon creating or refreshing a non-production R/3 system, these entries should be established in table ZEHCAT so that all email is discarded. Changes can later be made to support specific testing.ZEHCAT
entriesMANDTHNCATCMODEACTION<ALL OTHER FIELDS><client><space><space>XX<space><client>++XX<space>

5.  The

...

Tables

Programmers may view or modify the contents of the ZEMCTRL and ZEHCAT tables via utility program ZBRSMAIL. This program presents the following modification options for each table:

  1. Delete all rows of the table.
  2. Replace all table contents with the contents of a file.
  3. Append a file to the table.
  4. Write all table contents to a file.
  5. Do nothing. In addition to the above options, ZBRSMAIL presents the following additional modification option for table ZEHCAT:
  6. Modify all rows where email handling category, HNCAT, matches a select-option.

...