public static async Task <bool> SendEmail(string subject, string message, string toemail, bool IsHTML = true)
        {
            var NewTask = new Task <bool>(() =>
            {
                //string smtpServer = "smtp-mail.outlook.com";

                var UserMail     = MailUser;     //"*****@*****.**";
                var UserPassword = MailPassword; //"Balittanah123";

                try
                {
                    //Send teh High priority Email
                    EmailManager mailMan = new EmailManager(MailServer, MailPort);

                    EmailSendConfigure myConfig = new EmailSendConfigure();
                    // replace with your email userName
                    myConfig.ClientCredentialUserName = UserMail;
                    // replace with your email account password
                    myConfig.ClientCredentialPassword = UserPassword;
                    myConfig.TOs             = new string[] { toemail };
                    myConfig.CCs             = new string[] { };
                    myConfig.From            = UserMail;
                    myConfig.FromDisplayName = "[Faasri] - Seat Management";
                    myConfig.Priority        = System.Net.Mail.MailPriority.Normal;
                    myConfig.Subject         = subject;

                    EmailContent myContent = new EmailContent();
                    myContent.Content      = message;
                    myContent.IsHtml       = IsHTML;
                    mailMan.SendMail(myConfig, myContent);
                    Logs.WriteLog("email notification result: email was sent successfully");
                    return(true);
                }
                catch (Exception ex)
                {
                    Logs.WriteLog("email notification result: " + ex.Message);
                    return(false);
                }
            });

            NewTask.Start();
            return(await NewTask);
        }
        // Put the properties of the email including "to", "cc", "from", "subject" and "email body"
        private MailMessage ConstructEmailMessage(EmailSendConfigure emailConfig, EmailContent content)
        {
            MailMessage msg = new System.Net.Mail.MailMessage();

            foreach (string to in emailConfig.TOs)
            {
                if (!string.IsNullOrEmpty(to))
                {
                    msg.To.Add(to);
                }
            }

            foreach (string cc in emailConfig.CCs)
            {
                if (!string.IsNullOrEmpty(cc))
                {
                    msg.CC.Add(cc);
                }
            }

            msg.From = new MailAddress(emailConfig.From,
                                       emailConfig.FromDisplayName,
                                       System.Text.Encoding.UTF8);
            msg.IsBodyHtml      = content.IsHtml;
            msg.Body            = content.Content;
            msg.Priority        = emailConfig.Priority;
            msg.Subject         = emailConfig.Subject;
            msg.BodyEncoding    = System.Text.Encoding.UTF8;
            msg.SubjectEncoding = System.Text.Encoding.UTF8;

            if (content.AttachFileName != null)
            {
                Attachment data = new Attachment(content.AttachFileName,
                                                 MediaTypeNames.Application.Zip);
                msg.Attachments.Add(data);
            }

            return(msg);
        }
        public void SendMail(EmailSendConfigure emailConfig, EmailContent content)
        {
            MailMessage msg = ConstructEmailMessage(emailConfig, content);

            Send(msg, emailConfig);
        }