Skip to Content

SAP Sourcing Custom Mail Message Templates


Email notifications is an integral part of SAP Sourcing / CLM used in several places within the application. They are controlled by Mail Configurations and Mail Message Templates.  The trigger for these notifications is predetermined by the system. But often times there are business requirements that require custom email notifications to be sent out when a particular action is performed by the end user. For instance, when the Contract document is moved to the Legal Review phase, you may want to send out an email notification to notify the Legal team. Prior to Sourcing 7.0 SP3, this requirement would have been accomplished by writing a script and using java’s mail class. This is totally a fine approach, but the issue is, you have minimal control on when the email notifications should go out. For example, you may be performing some testing in your QA system and you don’t want emails to go out. Unfortunately, as long as the script containing the email code is triggered, the email will go out even when the mail daemon is turned off. This may not be ideal.

Starting from Sourcing 7.0 SP3 onwards SAP provides a better way to send out custom mail messages using the new custom Mail Message Templates. There are ten custom Mail Message Templates that are available. Each custom Mail Message Template comes with five custom tokens which can be used to include any metadata in the message body.

Now let’s take a look at what needs to be done in order to use the custom Mail Message Template. I will use Custom Template 1 as an example.

Step 1

The first step would be to add the desired content to the custom Mail Message Template. This is done by going to setup page > Mail Message Template > Select Custom Template 1 and duplicating it and saving it as new template. Now, populate the subject field and the body of the message with the desired text and other required fields and save the template. The Purpose, Sender, Recipient fields on the custom template are blank and cannot be populated. That is because these custom mail message templates can be can basically be used for any purpose.

Note, you can use TOKEN1 through TOKEN5 within the message body and in the subject. The syntax for the tokens is same as other mail message tokens.


The message is to inform you that master agreement name %TOKEN1% is now in the %TOKEN2% status. Please logon to CLM and review the contract document.

Step 2

Add the Mail Message Template to the Mail Configuration. From setup page go to Mail Configuration > edit the Mail Configuration. Now point the Custom Template 1 to the template you had created in step 1 and save the Mail Configuration.

Step 3

Now, it’s time to write the script that will call the custom mail message template 1. Depending on when the mail notification should be sent out, first select the appropriate script target. The line of code that is of most interest to us that sends mail notifications is the NotificationUtil class’s sendNotification method.

Here’s the method signature

12-7-2012 11-46-45 AM.png

Let’s take a look at the code snippet below:

Line 1: Properties params = new Properties();

Line 2: params.put(new String(“TOKEN1”), doc.getDisplayName());

Line 3: String[] recipients = {““};

Line 4: sender = session.getAccount();

Line 5: mailTypeEnum = new MailTypeEnumType(MailTypeEnumType.ODP_CUSTOM_TEMPLATE1);

Line 6: NotificationUtil.sendNotification(recipients,sender, mailTypeEnum,params,null,null);

Lines 1 and 2 uses java Properties to store key value pairs that contains token name and its corresponding value. Line 3 is the email recipients. Sender in this case is the current user, so line 4 gets a reference to the current user. In line 5, we are saying we will use custom template 1. sendNotification method on line 6 is responsible for sending the email notification. The last two parameters are null because we are not dealing with attachments in the email. If you would like to attach a document to the email, the attachment name and the InputStream would have to be passed.

Hope this blog gives you a good idea on how to use and take advantage of the custom mail message templates.

12-7-2012 11-46-45 AM.png
You must be Logged on to comment or reply to a post.
  • Hi Vikram,

    Thanks for the Excellent Post.

    I have implemented the same code for custom email trigger but getting error “Error in method invocation: Static method sendNotification( java.lang.String,,, java.util.Properties, null, null ) not found in class ‘’ “.

    Can you please suggest why i am getting this error message.



  • Hi Vikram- This is a very helpful post. I have a question on using the global tokens like DOCUMENT_URL or OWNER_FIRST_LAST_NAME in the custom mail message templates. If I insert them into the custom mail template – would they automatically get resolved when the mail is being sent (since they are global mail tokens) or will i have to set their value in the script?



  • Hi Vikram,

    Thanks a lot for this blog. Very helpful!

    One question: Do you know if it is possible to introduce HTML tags into the custom mail’s body?

    Thanks and best regards,