IT:AD:K2:Development:HowTos:Create Emails

K2 has a built-in E-mail Event which is easy to use by following the wizard. The message body can be built in either HTML or Plain Text. Here is a way to use a template for more complicated message body.

First, create an html page as email template in the code project. Here is an example:

<html>
  <head><title></title></head>
  <body style="font-family:Verdana Arial;font-size:0.8em">
    <p style="font-family:Verdana Arial;font-size:0.8em">
     The following Request has been received by $Location Team. 
     Please follow the instructions below to enable the Request to be processed:
     <br /><br />
    $Comments
    </p>
    <br/><br />
    <p style="font-family:Verdana Arial;font-size:0.8em">$CurrentUserName<br />p>
    <br/><br />
    <p style="font-family:Verdana Arial;font-size:0.7em">
      CAUTION - This message may contain privileged and confidential information 
      intended only for the use of the addressee named above. 
      If you are not the intended recipient of this message you are hereby 
      notified that any use, dissemination, distribution or reproduction of this 
      message is prohibited. 
      This email was sent by CORP. Any views expressed in this 
      message are those of the individual sender and may not necessarily 
      reflect the views of CORP.
    </p>
  </body>
</html>

Fields prefixed with $ is the value field going to be set in code.

Then create a resource file and add this template. In code, replace the fields prefixed with $ with the real value.

string messageBody = Resources.Templates.EmailTemplate; // read from resource file
messageBody = messageBody.Replace("$Location","Wellington");
messageBody = messageBody.Replace("$Comments", processInstance.DataFields[Constants.COMMENTS].Value.ToString());
messageBody = messageBody.Replace("$CurrentUserName", processInstance.DataFields[Constants.CURRENT_USER_NAME].Value.ToString());

Create a DataField to capture the Message Body and simply drag this DataField to the Message Body page of Email Event Wizard.

  • /home/skysigal/public_html/data/pages/it/ad/k2/howto/create_emails.txt
  • Last modified: 2023/11/04 22:59
  • by 127.0.0.1