CodeCharge StudioYou previously added the necessary code that sends email notification to the assignee upon recording a new task in the system. We shall now implement similar functionality in After Update Event to notify the assignee when an existing task is updated and reassigned to someone.
if(ExecuteFlag&&!ErrorFlag&&DBUtility.UserId.ToString() != item.user_id_assign_to.Value.ToString())
{
SqlCommand userEmail = new SqlCommand("SELECT email FROM " +
"employees WHERE emp_id=" + DBUtility.UserId,
Settings.IntranetDBDataAccessObject);
SqlCommand assignedUserEmail = new SqlCommand("SELECT email FROM " +
"employees WHERE emp_id=" + item.user_id_assign_to.Value.ToString(),
Settings.IntranetDBDataAccessObject);
System.Web.Mail.MailMessage newMessage = new System.Web.Mail.MailMessage();
newMessage.From = userEmail.ExecuteScalar().ToString();
newMessage.To = assignedUserEmail.ExecuteScalar().ToString();
newMessage.Subject = " A task was assigned to you";
newMessage.BodyFormat = System.Web.Mail.MailFormat.Html;
newMessage.Body = "The following task was assigned to you:<br><br>" +
"Task ID :" + Request.QueryString["task_id"].ToString() +
"<br><br>"+ item.task_desc.Value;
System.Web.Mail.SmtpMail. SmtpServer = "localhost";
System.Web.Mail.SmtpMail.Send(newMessage );
}
If ExecuteFlag AndAlso (Not ErrorFlag) AndAlso Convert.ToString (DBUtility.UserId) <> Convert.ToString(item.user_id_assign_to.Value) Then
Dim userEmail, assignedUserEmail As String
userEmail = Convert.ToString(Settings.IntranetDBDataAccessObject.ExecuteScalar( _
"SELECT email FROM employees WHERE emp_id=" & DBUtility.UserId))
assignedUserEmail = Convert.ToString(Settings.IntranetDBDataAccessObject.ExecuteScalar( _
"SELECT email FROM employees WHERE emp_id=" & Convert.ToString(item.user_id_assign_to.Value)))
Dim newMessage As New System.Web.Mail.MailMessage()
newMessage.From = userEmail
newMessage.To = assignedUserEmail
newMessage.Subject = "A task was assigned to you"
newMessage.BodyFormat = System.Web.Mail.MailFormat.Html
newMessage.Body = "The following task was assigned to you :<br><br> Task ID :" & _
Convert.ToString(Request.QueryString("task_id")) & "<br><br>" & item.task_desc.Value
System.Web.Mail.SmtpMail. SmtpServer = "localhost"
System.Web.Mail.SmtpMail.Send(newMessage)
End if
The main differences between the above code and the one you used in After Insert event are as follows:
http://localhost/TaskManager/tasks_maint.aspx?task_id=9
Next: Test Email Delivery