public MainPage()
        {
            this.InitializeComponent();

            Chilkat.Mht mht = new Chilkat.Mht();

            textBox.Text = mht.Version;
        }
        public async Task <ActionResult <Models.APICallResult> > sendDirectiveEMailMessage(int motionId)
        {
            SqlConnection objSqlConnection1 = null;
            SqlConnection objSqlConnection2 = null;
            SqlCommand    objSqlCommandGetMotionRecipients;
            SqlCommand    objSqlCommandUpdateMotionRecipient;
            SqlDataReader objSqlDataGetMotionRecipients;

            System.Text.StringBuilder sbCommandText;
            Chilkat.Mht     objChilkatMht;
            Chilkat.Email   objChilkatEmail;
            Chilkat.MailMan objChilkatMailMan;
            HashSet <int>   hsSentMotionRecipient;

            Models.APICallResult apiCallResult = new Models.APICallResult();

            try
            {
                objSqlConnection1 = new SqlConnection(this._configuration["ConnectionStrings:MotionManager"]);
                await objSqlConnection1.OpenAsync();

                objSqlConnection2 = new SqlConnection(this._configuration["ConnectionStrings:MotionManager"]);
                await objSqlConnection2.OpenAsync();

                sbCommandText = new System.Text.StringBuilder();
                sbCommandText.Append("UPDATE MotionRecipient ");
                sbCommandText.Append("  SET NotificationSent = 1 ");
                sbCommandText.Append("  WHERE MotionRecipientID = @MotionID ");

                objSqlCommandUpdateMotionRecipient             = objSqlConnection1.CreateCommand();
                objSqlCommandUpdateMotionRecipient.CommandText = sbCommandText.ToString();
                objSqlCommandUpdateMotionRecipient.Parameters.Add(new SqlParameter("@MotionID", System.Data.SqlDbType.Int));
                objSqlCommandUpdateMotionRecipient.CommandTimeout = 600;
                objSqlCommandUpdateMotionRecipient.Prepare();

                sbCommandText = new System.Text.StringBuilder();
                sbCommandText.Append("SELECT MR.MotionRecipientID, TR.TargetName, TR.ContactEMailAddress ");
                sbCommandText.Append("  FROM MotionRecipient MR INNER JOIN TargetRecipient TR ON MR.TargetRecipientID = TR.TargetRecipientID ");
                sbCommandText.Append("  WHERE MR.MotionID = @MotionID ");

                objSqlCommandGetMotionRecipients             = objSqlConnection2.CreateCommand();
                objSqlCommandGetMotionRecipients.CommandText = sbCommandText.ToString();
                objSqlCommandGetMotionRecipients.Parameters.Add(new SqlParameter("@MotionID", System.Data.SqlDbType.Int));
                objSqlCommandGetMotionRecipients.CommandTimeout = 600;

                objSqlCommandGetMotionRecipients.Parameters[0].Value = motionId;
                objSqlDataGetMotionRecipients = objSqlCommandGetMotionRecipients.ExecuteReader();

                if (objSqlDataGetMotionRecipients.HasRows)
                {
                    objChilkatMht     = new Chilkat.Mht();
                    objChilkatMailMan = new Chilkat.MailMan();

                    objChilkatMht.UnlockComponent(ApplicationValues.TCH_CHILKAT_UNLOCK_CODE);
                    objChilkatMailMan.UnlockComponent(ApplicationValues.TCH_CHILKAT_UNLOCK_CODE);

                    objChilkatMailMan.SmtpHost = this._configuration["AppSettings:SMTPHostName"];
                    objChilkatMailMan.SmtpPort = int.Parse(this._configuration["AppSettings:SMTPPort"]);

                    if (this._configuration["AppSettings:SMTPAuthenticate"] == "true")
                    {
                        objChilkatMailMan.SmtpUsername = this._configuration["AppSettings:SMTPUserName"];
                        objChilkatMailMan.SmtpPassword = this._configuration["AppSettings:SMTPPassword"];
                    }

                    objChilkatMailMan.SmtpSsl  = (this._configuration["AppSettings:SMTPUseSSL"] == "true");
                    objChilkatMailMan.StartTLS = (this._configuration["AppSettings:SMTPIssueStartTLS"] == "true");

                    if (!string.IsNullOrEmpty(this._configuration["AppSettings:SMTPLogonDomain"]))
                    {
                        objChilkatMailMan.SmtpLoginDomain = this._configuration["AppSettings:SMTPLogonDomain"];
                    }

                    string strBaseUrl = string.Format("{0}://{1}{2}", Request.Scheme, Request.Host, Request.PathBase);
                    string strUrl     = string.Format("{0}/{1}/{2}/", strBaseUrl, "render/directiveEMailMessage", motionId);

                    objChilkatEmail = new Chilkat.Email();

                    objChilkatEmail.SetFromMimeText(objChilkatMht.GetEML(strUrl));

                    hsSentMotionRecipient = new HashSet <int>();
                    while (await objSqlDataGetMotionRecipients.ReadAsync())
                    {
                        objChilkatEmail.AddTo(objSqlDataGetMotionRecipients.GetString(1), objSqlDataGetMotionRecipients.GetString(2));
                        hsSentMotionRecipient.Add(objSqlDataGetMotionRecipients.GetInt32(0));
                    }       // while (await objSqlDataGetMotionRecipients.ReadAsync())

                    objChilkatEmail.From    = this._configuration["AppSettings:DirectiveEMailFromAccount"];
                    objChilkatEmail.Subject = this._configuration["AppSettings:DirectiveEMailSubjectText"];


                    //Chilkat.Task objChilkatTask = objChilkatMailMan.SendEmailAsync(objChilkatEmail);
                    //if (objChilkatTask.LastMethodSuccess)
                    if (objChilkatMailMan.SendEmail(objChilkatEmail))
                    {
                        foreach (int intMotionRecipientID in hsSentMotionRecipient)
                        {
                            objSqlCommandUpdateMotionRecipient.Parameters[0].Value = intMotionRecipientID;
                            await objSqlCommandUpdateMotionRecipient.ExecuteNonQueryAsync();
                        }
                    }
                    else
                    {
                        // PROGRAMMER's NOTE:  need to log error
                        return(StatusCode(StatusCodes.Status500InternalServerError, objChilkatMailMan.LastErrorText));
                    };
                }
                objSqlDataGetMotionRecipients.Close();

                apiCallResult.resultCode = APICallResult.RESULT_CODE_SUCCESS;

                return(Ok(apiCallResult));
            }
            catch (Exception ex1)
            {
                return(StatusCode(StatusCodes.Status500InternalServerError, ex1.Message));
            } finally
            {
                if (objSqlConnection1.State == System.Data.ConnectionState.Open)
                {
                    objSqlConnection1.Close();
                }
                if (objSqlConnection2.State == System.Data.ConnectionState.Open)
                {
                    objSqlConnection2.Close();
                }
            }
        }       // sendDirectiveEMailMessage()