Copyright 2020 - BV TallVision IT

Email body content doesn't support a lot of formatting options. If you are trying to use Italics or bold characters for example, I wouldn't know where to start. But then there is HTML, which supports the finest formatting options in the business. 

Note that not all email inboxes will support HTML emails, but it has become a more and more accepted format. So how does this work ? 

  1. Compose an email body in HTML, thus something like:
    <html>
    <head></head>
    <body> <p>Dear madam, sir, <p>As you <b>May have seen</b> there is a lot going on. </body> </html>
  2. Set the document type to 'HTM' (normally defaulted to 'RAW') like so:
    * Link the body text to the email, with document type HTM
            cl_document_bcs=>create_from_text(
              EXPORTING
                i_documenttype = 'HTM'
                i_text         = gt_email_body
                i_subject      = gv_subject
              RECEIVING
                result = lo_document ).
    

Follow the "More mail" approach in the previous paragraph and an email in HTML format will be produced.

Utilizing HTML

There are MANY websites on HTML and you may find my personal favorite w3schools.com very helpful. Here are a few simple email body enhancers, just to show you HTML is a suitable candidate for formatted emails:

Bold and Italics

Use HTML tags <B> and </B> to show text in Bold and <I>, </I> for Italics. <b>Bo<i>ld</b>it<u>al</i>cs</u> will show like this: Bolditalcs.

Horizontal line

The <hr> tag (required no end) will display a horizontal line. 

Style sheet adaptions

The really flexible formatting matters are arranged in a style sheet. The font to be used, the color of an <hr> line, the possibilities seem endless. Lets set the font and font-size on out email:

 
<html>
<head>
<style>
  body { font-family:arial; font-size:14pt; }
  hr { background-color:purple;height:4px;width:75% }
</style>
</head>
<body>
<p>Dear madam, sir,
<p>As you <b>May have seen</b> there is a lot going on. 
<hr>
<p>More below the line.. </body> </html>

This effectively sets the default font and font size for the BODY of the document (everything between body-tags). The hr color is set to purple, the height of the line is adjusted and the line is displayed at 75% of the width of the canvas. The above example:

Embedded images

It's even possible to embed an image in HTML coding, which is ignored by an email giant like Gmail.com (august 2016), but nevertheless, it demonstrates endless possibilities. Send out your email as a dedicated single page website, which may well include links.

Workflow task - as HTML email

When you're familiar with Workflow, the SELFITEM / SENDTASKDESCRIPTION should not be new to you. It's the business object and task that the system will suggest if you want to send an email from workflow. This email too can be transformed into an HTML email. Here's how:

  1. First of all, add your "send email" task to your workflow and make sure it sends mail.
  2. Then go to the task that was created for you, which will hold the SELFITEM / SENDTASKDESCRIPTION references. Change the task description.
    Note that this description is in fact the body or content of your email.
  3. The next bit is quite important and can easily be overlooked: the description is in fact a SapScript text, which can hold statements or instructions. For this setup to work, the instruction MAIL_HTML needs to be filled in as first line.
    To do this - go to "Change editor" to get the old-style - editor. Fill in the MAIL_HTML
    /: MAIL_HTML
    
    Where the /: bit is very important. It's the way you can instruct the SENDTASKDESCRIPTION method to work with the HTML format.
  4. The line setup for HTML and classic SapScript texts is quite different. For one - the HTML formatting doesn't have end-of-lines, unless you put them in (e.g. with <br>).
  5. Old-style lines will start with a * as formatting option. HTML formatted lines need to start with /*. So: if your email content is fully composed of HTML matter - make sure each line has a /* format.

This will send your mail as HTML ! A short -ready to demonstrate example:

/: MAIL_HTML
/* <html><body>
/* <p style="font-size:34pt;color:red;">Hello world !
/* </html></body>