1. Database fields

Add the IsEMailUnSent field in the WfTasks table to indicate whether the email is sent.

Email field in the SysUser table to read the email address of the person who handles the task.

Add PageUrl in the WfProcess table to determine the link address in the email template.

  1. HangFire Jobs

Add a HangFire scheduled task job and add a scheduled task job every minute. You can see the execution status of the job from the Dashboard.

  1. Email template

Including email title and email body information, see the example in the JobAdminDefine.cs file. Considering the diverse needs of enterprise users, developers can make customized extensions here.

privatestaticreadonlystring Title = "New to-do reminder email!" ;

privatestaticreadonlystring Content = @"< h1 >New to-do task reminder</h1>" +

"<p>You have a new to-do task: " +

"<a href='{0}'>Business document name and document serial number</a>" +

"Please log in to the business system in time for processing! Thank you!</p>" ;


privatestaticreadonlystring SendEMailAccount = "test@abc.com" ;

privatestaticreadonlystring SendEMailPassword = "123456" ;

privatestaticreadonlystring SendEMailHost = "smtp.abc.com" ;

privatestaticreadonlyint SendEMailHostPort = 25;

  1. Asynchronous email sending code

Email sending is performed as a background job of the system, and in an asynchronous manner, which can meet the cyclic processing mode of batch data and leave room for future performance expansion of the system. Specific code examples are as follows:

///<summary>

/// Send email notification for to-do tasks

///</summary>

public void SendTaskEMail( IList < ProcessEntity > processList,

IList <UserEMailEntity> userList )

{

var wfService = new WorkflowService ();

var taskList = wfService.GetTaskListEMailUnSent();

if (taskList != null && taskList.Count() > 0)

{

foreach ( var task in taskList)

{

Func < TaskViewEntity , IList < ProcessEntity >, IList < UserEMailEntity >, Task > func = SendEMailAsync;

BackgroundTaskRunner .FireAndForgetTaskAsync(func, task, processList, userList);

}

}

}