There are business requirements where you need to generate emails with or without attachments based on a custom logic in...
Contents Introduction .................................................................................................................................................. 2 Basics steps to follow .................................................................................................................................... 2 Example ..................................................................................................................................................... 2 Steps to follow .......................................................................................................................................... 3 Data definition ...................................................................................................................................... 3 Have data/text ready for email body .................................................................................................... 3 Have an internal table ready with attachment data............................................................................. 4 Convert internal table with attachment data into a binary stream ..................................................... 4 Set the email request subject ............................................................................................................... 5 Create the email document .................................................................................................................. 5 Set the email request attributes ........................................................................................................... 5 Attach the email document to the email request ................................................................................ 6 Create and set the email sender ........................................................................................................... 6 Add the attachment to the email document ........................................................................................ 6 Create and set the email recipients ...................................................................................................... 6 Send the email request and commit work ............................................................................................ 7 Check the created email in the transaction SOST ................................................................................. 7
Introduction There are business requirements where you need to generate emails with or without attachments based on a custom logic in an ABAP program.
Basics steps to follow
Data definition
Have text ready for email body
Have internal table ready with data for the attachment
Convert table data into a binary stream
Set them email request subject
Create the email document
Attach the email document to the email request
Create the email sender and set the sender
Add the attachment to email document
Create recipients and set recipients
Send email request and commit
Example Send an email using sample content and an attachment. Check the email in SOST to verify.
Steps to follow Data definition Define data set to be used in the program. See program comment for details.
Have data/text ready for email body In this example, an internal table will be populated with sample data for the email body.
Have an internal table ready with attachment data
Convert internal table with attachment data into a binary stream Collect internal table data to a variable type String. Separate values by horizontal tab and add a new line character at the end of each line.
Set the email request subject Two variable will be used in two different methods because of different types.
Create the email document Determine the length of the email body (In this example LT_CONTENTS internal table). Document type is RAW and you may use a different type as per your requirement. Parse email body table, determined length of the table, document subject, language and importance of the message.
Set the email request attributes
Attach the email document to the email request
Create and set the email sender In this example sender is the user who runs this program.
Add the attachment to the email document Parse the attachment document extension, attachment name and the converted binary stream.
Create and set the email recipients
Send the email request and commit work
Check the created email in the transaction SOST
Author: Harsha Thelikorala E-Mail:
[email protected]/
[email protected] Website: www.learnsaptips.com LinkedIn: View my profile in LinkedIn
Disclaimer This article is done based on my research and readings, unless otherwise stated. The views expressed are my own and not of anyone else. Author accepts no liability for the content of the articles in this website or for the consequences of any actions taken on the basis of the information provided. Using this information is at the users own discretion and responsibility.