Step by Step Process of Preparing E-mail with HTML body and HTML Attachment

作者:郑德鼎 约 5 分钟阅读 更新日期:2024-02-22 2 年前更新 标签:工具, 技术

Step by Step Process of Preparing

E-mail with HTML body and HTML

Attachment

Applies to

This document applies to SAP ECC 6.0 incl. EhP3. For more information, visit the ABAP homepage.

Summary

This paper gives a step by step process of preparing an E-mail with an HTML body and HTML attachment

and sending it to multiple E-mail ids.

Author: Sri Hari Anand Kumar

Company: Applexus Technologies

Created on: 23 March 2011

Author Bio

Sri Hari Anand Kumar is working as a SAP Technology Consultant in Applexus Technologies with an

experience of 6 months in ABAP and 3 months in SAP HCM.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 1

Step by Step Process of Preparing E-mail with HTML body and HTML Attachment

Table of Contents

Introduction ......................................................................................................................................................... 3

Step in Preparing the Mail .................................................................................................................................. 3

Step 1: Create Persistent ................................................................................................................................ 3

Step 2: Create Document................................................................................................................................ 3

Step 3: Add Attachment .................................................................................................................................. 4

Step 4: Set Document ..................................................................................................................................... 4

Step 5: Set Sender .......................................................................................................................................... 5

Step 6: Add Recipient ..................................................................................................................................... 5

Step 7: Set Send Immediately ........................................................................................................................ 6

Step 8: Send ................................................................................................................................................... 6

Related Content ................................................................................................................................................ 10

Disclaimer and Liability Notice .......................................................................................................................... 11

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 2

Step by Step Process of Preparing E-mail with HTML body and HTML Attachment

Introduction

Normally mails are sent using function modules

SO_DOCUMENT_SEND_API1

SO_NEW_DOCUMENT_ATT_SEND_API1

SO_NEW_DOCUMENT_SEND_API1 and

SO_OBJECT_SEND

These are few older function modules which are being used. In this paper I will be discussing about the class

concept of sending mails.

Basically two classes are used here.

Class CL_BCS: Serves as interface from BCS to applications.

Class CL_DOCUMENT_BCS: Used for attachment and also for creating the body of the mail.

There are few methods which are used in these class for preparing these mails which is discussed in detail

below

Step in Preparing the Mail

Step 1: Create Persistent

The CREATE_PERSISTENT method of the class CL_BCS is used to create a persistent send request for

the mail which we are going to send.

Sample code how to create the persistent request using this method of the class.

v_send_request = cl_bcs=>create_persistent( ).

As a result the return parameter of this above method creates an instance of class CL_BCS with the instance

of send request.

Step 2: Create Document

The CREATE_DOCUMENT method of the class CL_DOCUMENT_BCS is used to create the content which

needs to be displayed in the mail body and also the attachment of the E-mail.

Using this class CL_DOCUMENT_BCS we can create an instance and reference of this instance is passed

to SET_DOCUMENT method of the class CL_BCS.

CREATE_DOCUMENT method has few importing parameters they are

 i_type: Specifies the type of document which we are doing to create (for what all type of

document we can create see table TSOTD).

 i_subject: Subject of the mail which we are sending

 i_length: Length of the document in bytes which is an optional parameter

 i_language: Language in which the document needs to be created which is an optional

parameter.

 i_importance: Priority of the mail It is also optional parameter. (1 – High priority, 5 – medium

priority, 9 low priority. The default value is '5'.).

 i_sensitivity: Confidentiality of the mail which is also an optional parameter.( P – ,

F – functional, O – standard).

 i_text: This is the contents which need to be displayed in the body of the mail and in text

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 3

As a result the return parameter of this above method creates an instance of class CL_BCS with the instance

of send request.

Step by Step Process of Preparing E-mail with HTML body and HTML Attachment

format which is also an optional parameter. We need to pass a table with lines of

length of 255 characters

 i_hex: This is the contents which need to be displayed in the body of the mail and in binary

format which is also an optional parameter. We can pass a table with lines of length

of 255 characters.

 i_sender: Reference address of the mail being sent.

Sample code to create a document using this method.

v_document = cl_document_bcs=>create_document(

i_type = „HTM‟ “Since it is an HTML body

i_importance = „5‟

i_text = t_html

i_subject = „HTML Mail‟).

Here v_document is the reference variable for the method CREATE_DOCUMENT of the class

CL_DOCUMENT_BCS and t_html is a table with line of length 255 and will be having the contents which

needs to be displayed in the body.

Step 3: Add Attachment

The ADD_ATTACHMENT method in class CL_DOCUMENT_BCS is used to add an attachment to the

reference variable created using the method CREATE_DOCUMENT of the class CL_DOCUMENT_BCS.

ADD_ATTACHMENT method has few importing parameters, they are

 i_attachment_type: This is same as the i_type of the CREATE_DOCUMENT method.

 i_attachment_subject: The name of the attachment.

 i_attachment_size: Size of the attachment which is also an optional parameter.

 i_language: The language of the attachment which is an optional parameter.

 i_attachment_text: If the created attachment content is in text format. This is an optional

parameter.

 i_attachment_hex: If the created attachment content is in binary format. This is an optional

parameter.

Sample code to add an attachment to the created document using this method

CALL METHOD v_document->add_attachment

EXPORTING

i_attachment_type = „HTM‟ “Since it is an HTML attachment

i_attachment_subject = „HTML Attachment‟

i_att_content_text = t_html1.

Here t_html1 is a table with line of length 255 and will be having the contents which needs to be attached

to the mail.

Step 4: Set Document

The SET_DOCUMENT method in class CL_BCS is used to pass an object to the send request created using

CREATE_PERSISTENT method of the class CL_BCS. The SET_DOCUMENT method has only one

importing parameter i_document where we will be passing the attachment which we have created.

Sample code to set the document using this method

CALL METHOD v_send_request->set_document( v_document )

Here v_document is the reference variable which is passed to SET_DOCUMENT method.

SAP COMMUNITY NETWORK SDN - sdn.sap.com | BPX - bpx.sap.com | BOC - boc.sap.com | UAC - uac.sap.com

© 2011 SAP AG 4

v_document = cl_document_bcs=>create_document(

i_type = „HTM‟ “Since it is an HTML body

i_importance = „5‟

i_text = t_html

i_subject = „HTML Mail‟).

i_attachment_type = „HTM‟ “Since it is an HTML attachment

i_attachment_subject = „HTML Attachment‟

i_att_content_text = t_html1.

...

郑德鼎

关于作者:郑德鼎

企业信息化与 SAP 技术顾问,长期专注 SAP ABAP、FI/CO、MM、SD 等模块的技术分享与实战经验总结。查看更多介绍

来源说明:本文内容由「Step by Step Process of Preparing E-mail with HTML body and HTML Attachment.pdf」整理生成,仅用于内部技术分享与学习交流。