0% found this document useful (0 votes)
976 views3 pages

ABAP Program Which Sends An HTML Email From SAP System

This document contains an ABAP program that sends an HTML email from an SAP system. It includes code to import an image file from transaction SMW0, convert it to an XSTRING table, attach it to the HTML body, and send the email using BCS classes. The HTML email includes the embedded image and text. The program demonstrates how to combine HTML content with an image for emails sent from SAP.

Uploaded by

ankurbhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
976 views3 pages

ABAP Program Which Sends An HTML Email From SAP System

This document contains an ABAP program that sends an HTML email from an SAP system. It includes code to import an image file from transaction SMW0, convert it to an XSTRING table, attach it to the HTML body, and send the email using BCS classes. The HTML email includes the embedded image and text. The program demonstrates how to combine HTML content with an image for emails sent from SAP.

Uploaded by

ankurbhatia
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Sign up for a GitHub account

Instantly share code, notes, and snippets.

Sign in

Create a gist now

weiserman / HTML Email in ABAP with Image


Created 3 years ago

This is an example ABAP program which sends an HTML email from SAP system. It includes an image which is uploaded via transaction
SMW0
HTMLEmailinABAPwithImage
1

*&*

*&ReportYMAIL

*&

*&*

*&

*&

*&*

8
9

REPORTymail.

10
11
12

"ImagetoXstringTableform

13

DATA:lv_obj_lenTYPEso_obj_len,

14

lv_graphic_lengthTYPEtdlength,

15

gr_xstrTYPExstring,

16

lv_offsetTYPEi,

17

lv_lengthTYPEi,

18

lv_diffTYPEi,

19

ls_solixTYPEsolix,

20

lt_solixTYPEsolix_tab.

21
22

*AttachimagetoHTMLbody

23

DATA:lv_filenameTYPEstring,

24

lv_content_idTYPEstring,

25

lt_soliTYPEsoli_tab,

26

ls_soliTYPEsoli.

27
28

*ClassforcobiningHMTL&Image

29

DATA:lo_mime_helperTYPEREFTOcl_gbt_multirelated_service.

30
31

*BCSclassforsendingmail

32

DATA:lo_bcsTYPEREFTOcl_bcs,

33

lo_doc_bcsTYPEREFTOcl_document_bcs,

34

lo_senderTYPEREFTOif_sender_bcs,

35

lo_recipientTYPEREFTOif_recipient_bcs,

36

lv_subjectTYPEso_obj_des.

37
38

*DataDeclaration

39

DATA:lfd_xstringTYPExstring,

40

lfd_objidTYPEw3objid,

41

lv_obkeyTYPEwwwdatatab,

42

lt_mime_rawTYPESTANDARDTABLEOFw3mime,

43

ls_mime_rawTYPEw3mime.

44
45
46

*ImporttheImageFile,thesearemaintainedintransactionSMW0

47

lv_obkeyobjid='ZUCT_ROUND_LOGO'.

48

lv_obkeyrelid='MI'.

49
50

CALLFUNCTION'WWWDATA_IMPORT'

51

EXPORTING

52

key=lv_obkey

53

TABLES

54

mime=lt_mime_raw

55

EXCEPTIONS

56

wrong_object_type=1

57

import_error=2

58

OTHERS=3.

59
60

*...buildalongxstring

61

IFsysubrcEQ0.

62

LOOPATlt_mime_rawINTOls_mime_raw.

63

CONCATENATElfd_xstringls_mime_rawlineINTOlfd_xstringINBYTEMODE.

64

ENDLOOP.

65

ENDIF.

66
67

*...splitxstringintolt_solixtable(whichisneedforemail)

68

CLEARgr_xstr.

69

lv_obj_len=xstrlen(lfd_xstring).

70

lv_graphic_length=xstrlen(lfd_xstring).

71

gr_xstr=lfd_xstring(lv_obj_len).

72
73

lv_offset=0.

74

lv_length=255.

75
76

CLEARlt_solix[].

77

WHILElv_offset<lv_graphic_length.

78

lv_diff=lv_graphic_lengthlv_offset.

79

IFlv_diff>lv_length.

80

ls_solixline=gr_xstr+lv_offset(lv_length).

81

ELSE.

82

ls_solixline=gr_xstr+lv_offset(lv_diff).

83

ENDIF.

84

APPENDls_solixTOlt_solix.

85

ADDlv_lengthTOlv_offset.

86

ENDWHILE.

87
88

*AttachimagetoHTMLbody

89

lv_filename='UCT_LOGO.gif'.

90

lv_content_id='UCT_LOGO.gif'.

91
92

CREATEOBJECTlo_mime_helper.

93

CALLMETHODlo_mime_helper>add_binary_part

94

EXPORTING

95

content=lt_solix"Xstringintableform

96

filename=lv_filename"filenametobegiventoimage

97

extension='GIF'"typeoffile

98

description='GraphicinGIFformat'"description

99

content_type='image/gif'"contenttype/Mimetype.Ifmimetypenotpresentinsystemthenneedtoaddthroughtcode:SMW0

100

length=lv_obj_len"lengthofimage

101

content_id=lv_content_id."contentidwouldbeusedinhtmlpart

102
103

*...createtheHTMLcontentforthebodyoftheemail

104

REFRESHlt_soli[].

105
106

CLEARls_soli.

107

ls_soli='<htmlxmlns="http://www.w3.org/1999/xhtml"xmlns:xfa="http://www.xfa.org/schema/xfatemplate/2.1/"><head></head>'.

108

APPENDls_soliTOlt_soli.

109
110

CLEARls_soli.

111

ls_soli='<body>'.

112

APPENDls_soliTOlt_soli.

113
114

CLEARls_soli.

115

CONCATENATE'<p>DearWarren<br>'''INTOls_soliSEPARATEDBYspace.

116

APPENDls_soliTOlt_soli.

117
118

CLEARls_soli.

119

ls_soli='<br><imgalt="companylogo"src="cid:UCT_LOGO.gif"/><br>'.

120

APPENDls_soliTOlt_soli.

121
122

CLEARls_soli.

123

CONCATENATE'<br>Regards</p></body>''</html>'INTOls_soliSEPARATEDBYspace.

124

APPENDls_soliTOlt_soli.

125
126

*...settheHTMLwithdescription

127

CALLMETHODlo_mime_helper>set_main_html

128

EXPORTING

129

content=lt_soli

130

filename='message.htm'"filenameforHMTLform

131

description='Emailmessage'."Title

132

133

"CreateHTMLusingBCSclassandattachhtmlandimageparttoit.

134

lv_subject='Thisisatestemailforincludinggraphics'."subject

135

lo_doc_bcs=cl_document_bcs=>create_from_multirelated(

136

i_subject=lv_subject

137

i_multirel_service=lo_mime_helper).

138
139

lo_bcs=cl_bcs=>create_persistent().

140
141

"CreateDocument

142

lo_bcs>set_document(i_document=lo_doc_bcs).

143
144

"createSender

145

lo_sender=cl_cam_address_bcs=>create_internet_address('[email protected]').

146
147

*Setsender

148

lo_bcs>set_sender(

149

EXPORTING

150

i_sender=lo_sender).

151
152

"CreateRecipient

153

lo_recipient=cl_cam_address_bcs=>create_internet_address(i_address_string='[email protected]').

154

lo_bcs>add_recipient(i_recipient=lo_recipient).

155
156

lo_bcs>send().

157

COMMITWORKANDWAIT.

Sign up for free

to join this conversation on GitHub. Already have an account? Sign in to comment

You might also like