Send E-mail in HTML format with dynamic e-mail body content
Applies to:
SAP Netweaver, ABAP, Email, standard text
Summary
This tutorial will take you step by step process to develop ABAP program which will send E mail in HTML format. The email body content is maintained separately in Std. text object; so that it can be maintained independent of Program.
With this; email is generated in HTM format which is more asthetic than a RAW format. Email body can be formatted with all rich text properties like bold, italic fonts, text sizes, tables, etc.
Additionally email body content can be changed without changing the ABAP program; since it is maintained separately in standard text. Program modularization & ease of maintenance can be achieved.
Author: Amit Talekar
Company: Capgemini India
Created on: 23rd July 2012
Create Standard text object
Create standard text object from /SO10
Maintain text with HTML tags
In this example HTML tags for table structure are maintained.
For dynamic contents; program global variables are used
Read std. text in ABAP Program
Call FM READ_TEXT
Using Standard Function module READ_TEXT read Std. text in the program.
READ_TEXT FM returns LS_HEAD & LT_LINES.
LS_HEAD contains Header data and LT_LINES contains text maintained in the object.
Call FM TEXT_SYMBOL_REPLACE
Call FM to replace variables in std. text with actual values.
FM TEXT_SYMBOL_REPLACE returns LT_LINES with values (passed as program global variables).
Send E-mail
Prepare E-mail subject & E-mail body
Call Std. FM to send E-mail in HTML format
Check the output in MS-Outlook
Please try posting code as text and not screen dumps, so people can easier try out what you are suggesting.
Also I would rather use the newer functionality of the CL_BCS class for sending mails than the older SO_NEW_DOCUMENT... function modules.
Thomas
Hello Thomas,
Thanks for pointing it out. In future I will take care of the same.
Amit
Hi Amit,
Good one.
Regards,
Madhu.
Hi Amit , thanks for the share ,
i am hoping you can give me some guidance on the following :
i have a user requirement to replace the following functionality we provide , the user when working with certain transactions have the option to send email
we provide the user with a standard text editor (like S000) which then use the text contents to be populated as the email body text with the outgoing email
now we want to provide them wth the ame functionality but use a HTML editor allwoingthe user much more functionality like bold , colour tools etc
can you help me please
thank you
Ravi
Excellent, thanks!
Best regards,
Bruno
Hi,
to be honest, it's better to use XSLT transformations to build HTML letters.
Kind regards,
Denis
Hi,
I have a similar feeling. There are multiple ways to create texts in XML-based format.
And I'm not so convinced about this: "Program modularization & ease of maintenance can be achieved."
How ease if maintanance can be achieved when you create manually HTML code in standard text ....
Regards, Radek
I was looking for a simple-to-be-used example for reading a Standard text from SO10 and replace the symbols from the current main program.
This blog helped me a lot here, although there was one piece missing for me, and another small correction:
- The program (sy-repid) needs to be transferred an the call to the replace-FM, otherwise it doesn't replace any program symbols
- The replace-FM doesn't need the sy-tfill. When not provided, it uses the complete table.
Thanks and best regards
Florin
Hi,
Is there any way to get the changed values of mail body in Outlook when it come back to SAP?
We are doing offline approval process using Outlook. In that case, User has to enter the OTP in a text box given in mail body. How can we get this OTP value when the user replies to mail?
Any help is appreciated.
Regards,
veena
Hi,
Followed the same process but the content in standard text is not displaying.
Please help.