private async Task SendEmail()

in TasksTracker.Processor.Backend.Svc/Controllers/TasksNotifierController.cs [47:86]


        private async Task<bool> SendEmail(TaskModel taskModel)
        {
            var integrationEnabled = _config.GetValue<bool>("SendGrid:IntegrationEnabled");
            var sendEmailResponse = true;
            var subject = $"Task '{taskModel.TaskName}' is assigned to you!";
            var plainTextContent = $"Task '{taskModel.TaskName}' is assigned to you. Task should be completed by the end of: {taskModel.TaskDueDate.ToString("dd/MM/yyyy")}";

            try
            {
                //Send actual email using Dapr SendGrid Outbound Binding (Disabled when running load test)
                if (integrationEnabled)
                {
                    IReadOnlyDictionary<string, string> metaData = new Dictionary<string, string>()
                {
                    { "emailTo", taskModel.TaskAssignedTo },
                    { "emailToName", taskModel.TaskAssignedTo },
                    { "subject", subject }
                };
                    await _daprClient.InvokeBindingAsync("sendgrid", "create", plainTextContent, metaData);
                }
                else
                {
                    //Introduce artificial delay to slow down message processing
                    _logger.LogInformation("Simulate slow processing for email sending for Email with Email subject '{0}' Email to: '{1}'", subject, taskModel.TaskAssignedTo);
                    Thread.Sleep(1000);
                }

                if (sendEmailResponse)
                {
                    _logger.LogInformation("Email with subject '{0}' sent to: '{1}' successfully", subject, taskModel.TaskAssignedTo);
                }
            }
            catch (System.Exception ex)
            {
                sendEmailResponse = false;
                _logger.LogError(ex, "Failed to send email with subject '{0}' To: '{1}'.", subject, taskModel.TaskAssignedTo);
                throw;
            }
            return sendEmailResponse;
        }