Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
Showing results for 
Search instead for 
Did you mean: 
Former Member

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!

Labels in this area