public WordPressHelper(UserManager <ApplicationUser> userManager,
                               IDbPortal DbPortal,
                               Ilog log,
                               IEmailSender emailSender)
        {
            _userManager = userManager;
            _DbPortal    = DbPortal;
            _log         = log ?? throw new ArgumentNullException(nameof(log));
            _emailSender = emailSender;

            WordPressBaseUri = _DbPortal.GetT_PRT_APP_SETTING("WORDPRESS_URI");
            UserName         = _DbPortal.GetT_PRT_APP_SETTING("WORDPRESS_USERNAME");
            Password         = Utils.Decrypt(_DbPortal.GetT_PRT_APP_SETTING("WORDPRESS_PWD"));
        }
        public bool SendEmail(string from, string to, List <string> cc, List <string> bcc, byte[] attach, string attachFileName, string emailTemplateName, List <emailParam> emailParams)
        {
            try
            {
                //************* GET SMTP SERVER SETTINGS ****************************
                string mailServer  = _DbPortal.GetT_PRT_APP_SETTING("EMAIL_SERVER");
                string Port        = _DbPortal.GetT_PRT_APP_SETTING("EMAIL_PORT");
                string smtpUser    = _DbPortal.GetT_PRT_APP_SETTING("EMAIL_SECURE_USER");
                string smtpUserPwd = _DbPortal.GetT_PRT_APP_SETTING("EMAIL_SECURE_PWD");

                //*************SET MESSAGE SENDER IF NOT SUPPLIED*********************
                if (from == null)
                {
                    from = _DbPortal.GetT_PRT_APP_SETTING("EMAIL_FROM");
                }

                //************GET EMAIL CONTENT FROM TEMPLATE******************************
                T_PRT_REF_EMAIL_TEMPLATE _temp = _DbPortal.GetT_PRT_REF_EMAIL_TEMPLATE_ByName(emailTemplateName);
                if (_temp != null)
                {
                    string subj = _temp.SUBJ;
                    string body = _temp.MSG;

                    foreach (emailParam _item in emailParams)
                    {
                        body = body.Replace("{" + _item.PARAM_NAME + "}", _item.PARAM_VAL);
                    }


                    //************** REROUTE TO SENDGRID HELPER IF SENDGRID ENABLED ******
                    bool SuccID = false;
                    if (mailServer == "smtp.sendgrid.net")
                    {
                        SuccID = SendEmailUsingSendGrid(from, to, cc, bcc, subj, body, smtpUserPwd).GetAwaiter().GetResult();
                    }
                    else
                    {
                        SuccID = SendEmailUsingSMTP(from, to, cc, bcc, attach, attachFileName, mailServer, Port, smtpUser, smtpUserPwd, subj, body);
                    }


                    //*************** LOG EMAIL SENT ****************************************
                    _log.InsertT_PRT_SYS_EMAIL_LOG(from, to, null, subj, null, emailTemplateName);  //TODO record success/failure

                    return(SuccID);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception ex)
            {
                if (ex.InnerException != null)
                {
                    _log.LogEFException(ex);
                }

                return(false);
            }
        }