Chapter 11. Sending E-mail Using BCS Classes

In this chapter, we will see recipes of e-mail programming using the Business communication services (BCS). We will look at:

  • Creating a simple e-mail message
  • Sending e-mail to Internet e-mail addresses
  • Adding attachments to your message
  • Creating HTML e-mail
  • Running a program and sending its output as an e-mail

Introduction

This chapter explores useful recipes related to the programming of e-mail sending. We will start with a brief overview of BCS and the various classes available. Then we will see a simple recipe that will generate an e-mail to an SAP user in his or her inbox. Then, we will show how the same program may be changed in order to send the e-mail to Internet e-mail addresses.

We will then add attachments such as an Excel (XML file) to the e-mail. Creating HTML documents will also be discussed. Finally, we will create a program that will execute another ABAP program, convert its output into PDF, and attach the PDF to an e-mail message.

We will see the most important and commonly used classes (and their methods) used for e-mail creation. In addition to e-mail programming classes such as CL_BCS and CL_BCS_DOCUMENT, we will also see classes such as CL_CONVERT_BCS that are used for converting files into appropriate formats suitable for attaching to e-mail documents.

Throughout the chapter, the terms e-mail and SAP Office Document will be used interchangeably.

The BCS classes provide a newer object-oriented means of generating e-mails programmatically. The function modules should no longer be used for sending e-mails. The BCS classes are much simpler to program, particularly when we have attachments involved.

The classes relevant to e-mail programming are discussed as follows:

Class name

Use

CL_BCS

This class is for creating sent requests. The document (e-mail body and attachments) is assigned to it and recipients are specified. Finally, the request is sent.

CL_DOCUMENT_BCS

This is the document class for specifying the content of the e-mail and attachments (if any).

CL_CAM_ADDRESS_BCS

This class provides a number of useful methods. The notable one uses an Internet e-mail address such as [email protected] and returns a recipient user object.

CL_SAPUSER_BCS

This class creates a recipient object based on an SAP user ID to be used.

CL_BCS_CONVERT

This class converts data from one format to another, such as conversion of text string to binary table or from a hexadecimal string to a binary table, and so on.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.142.250.203