Skip to Content

Some time ago I created a document about how to send custom email notification with attachment in SAP Cloud Applications Studio How to send an email with attachments in SAP Cloud Application Studio.

The body text in this example was plain text.

Now I want to show you how to send an HTML email.

Step 1.

Implement the Event-BeforeSave for your business object.

Step 2.

Write the following ABSL code:

import ABSL;

import AP.FO.Activity.Global as prop;

import AP.Common.GDT as GlobalDataTypes;

import BASIS.Global; //for the pdf

import DocumentServices.Global;

var elEmailRoot : elementsof EmailActivity; 

var elEmailParty: elementsof EmailActivity.Party;

var instEmail; 

var emailBody; 

var emailSubject; 

var elEmailTxtColl: elementsof EmailActivity.TextCollection;

var elEmailTxtCollTxt: elementsof EmailActivity.TextCollection.Text; 

var elEmailTxtCollTxtCntnt: elementsof EmailActivity.TextCollection.Text.TextContent; 

var instEmailTxtColl; 

var instEmailTxtCollTxt; 

var instEmailTxtCollTxtCntnt;

var instEmailAttFld;      

//Email instance creation

emailSubject = "Html test"; 

elEmailRoot.Name.content = emailSubject; 

instEmail = EmailActivity.Create(elEmailRoot);       

//Add parties

elEmailParty.PartyKey.PartyID.content = "8000000102"; 


elEmailParty.PartyKey.PartyID.content = "8000000020"; 


//Create att folder

instEmailAttFld = instEmail.AttachmentFolder.Create();

//Add attachment1 (html body)

var doctype : GlobalDataTypes:DocumentTypeCode;

var binaryObject : BinaryObject;

var docDesc : GlobalDataTypes:Description;

var docName : GlobalDataTypes:LANGUAGEINDEPENDENT_Name;

var docAltName : GlobalDataTypes:LANGUAGEINDEPENDENT_Name;

var bin : BinaryObject.content;

docName = "body.html";

doctype.content = "10001";

binaryObject.mimeCode = "text/html";

binaryObject.content = Binary.ParseFromString("<html><head></head><body><div style=\”font-weight:bold;\”>test</div><body></html>");

instEmailAttFld.CreateFile(doctype, docName, docAltName, docDesc, binaryObject);

//Add attachment 2(pdf)

var FormTemplateLanguage = "E";

var PDF : BinaryObject;

var FormTemplateCode : OutputRequestFormTemplateCode;

FormTemplateCode.content = "Y6Y527NH_PMH9V"; //Code is Form Template Header Code

// Reuse Service Call

PDF = OutputManagementUtilities.GetPDF(this,FormTemplateCode,FormTemplateLanguage);

docName = "test2.pdf";

doctype.content = "10001";

binaryObject = PDF;

instEmailAttFld.CreateFile(doctype, docName, docAltName, docDesc, binaryObject);


Step 3.

Here you go!


To report this post you need to login first.


You must be Logged on to comment or reply to a post.

  1. Former Member

    Hi Alessandro,

    Thanks for this tutorial. I am trying to send an HTML email (without attachments) and this is not working (using the exact same code as you are). We are on 1405, maybe something has changed?

    I opened up a topic as well: Send HTML email from C4C?

    Can you help me out?


      1. Jacques-Antoine Ollier

        Hello Alessandro,

        I cannot succeed in putting my body.html as a body text element.

        When I receive the emails, the document is still an attachment and is not added to the body of my email.

        I exactly used your code above. Is there any step to do in order to add this attachment as a body and not as an attachment of the email?

        Thank you very much for your attention.

        Best regards.


        1. Alessandro Iannacci Post author

          Hi Jacques, it depends on the email client (gmail is able to visualize it like a normal html email) however i did not find a way to remove the html from the attachments 🙁

          1. Jacques-Antoine Ollier

            Hello Alessandro and thank you for your permanent help!

            Even if I send the email to my iCloud account or Gmail account, it is the same. I have no body added, only an attachment.

            When you say: “however i did not find a way to remove the html from the attachments”, I can see that the “Test” you put in your binary object is appearing as a body text.

            Am I wrong?

            Because that is exactly what I need. I do not care if there is still an html attachment as long as I can retrieve the text I did put in it, directly in the email’s body.

            I raised another thread in order to discuss that:

            Thank you very much for your attention.

            Bets regards.


  2. Former Member

    Hi Alessandro,

    I have tried above code. But I got this Error.

    Error: The document you want to upload has the MIME type text/html. Documents with this MIME type are not allowed to be uploaded according to the settings made in your solution configuration.

    I hope, I miss some configuration. Can you help me to solve it?



    1. Former Member

      Hi San Ka Ran

      You need to add the mime type to the config.

      goto Business config WC -> first Implementation->fine tune -> search for Mime .

      Add the mime type code  in this setting .mime type.pngthis setting.

      1. Former Member

        hi Swapnil,

        Thanks. I have configured as you said. Even I got an same issue. Please help me to  solve this issue.

        Configuration and Error window Screen Shots :


                        1. Former Member

                          @Alessandro, In Other system, I have tried as you said. It is working perfectly.  Thanks a lot. I think problem in previous system. So I have raised an incident to SAP. once again thanks. 🙂 🙂 🙂

                  1. Former Member

                    Dear Alessandro,

                    HTML mail was successfully send in development system.

                    when i was configured in customer tenant. i got this error message while run the script

                    “The document you want to upload has the MIME type text/html. Documents with this MIME type are not allowed to be uploaded according to the settings made in your solution configuration”

                    also can you guide me where to find the Disable signing and encryption



  3. Hanumath K

    Hi Alessandro,

    I have a requirement to send an attachment (PDF Doc which is available on my system hard disk), can I do this without using the HTML body as attachment? If it is not then what I have to use as HTML body in that case.

    And also Can I get this PDF from one of my drives on the system? any syntax for the same will be helpful if. Thanks.



    1. Alessandro Iannacci Post author

      Hi! You cannot add an attachment to an email from your hard drive. The document needs to be available in the C4C System in one business object that you are processing as a binaryobject.

    1. Former Member

      Use this for BCC:

      var elEmailBCCParty: elementsof EmailActivity.Party;

      elEmailBCCParty.PartyKey.PartyID.content = “123”;


      Use this for CC:

      var elEmailCCParty: elementsof EmailActivity.Party;

      elEmailCCParty.PartyKey.PartyID.content = “12345”;


        1. Former Member

          You can create me than one.

          var elEmailBCCParty: elementsof EmailActivity.Party;

          elEmailBCCParty.PartyKey.PartyID.content = “123”;


          elEmailBCCParty.PartyKey.PartyID.content = “123456789”;


  4. Former Member


    Hi All,

    Since the EmailActivity is now deprecated, I am trying to make use of Activity BO to perform send mail, but could not achieve the same. i have these points unanswered:

    1. Without creating instance in Activity can I send the mail when Outlook is not configured?
    2. In Activity BO, Party.EmailURI is read only what can be done to specify the sender?

    Please guide.




Leave a Reply