//Send to just one address with text replacement
        public int SendDatabaseMail(string address, int emailID, int userID, string userName, string value1, string value2, string value3, string value4, bool no_duplicates_today)
        {
            // get email info
            qCom_EmailTool email      = new qCom_EmailTool(emailID);
            qCom_EmailItem full_email = new qCom_EmailItem(emailID);

            string header              = string.Empty;
            string footer              = string.Empty;
            string strFromEmail        = string.Empty;
            string fromName            = string.Empty;
            string emailUsername       = null;
            string emailPassword       = null;
            string emailServer         = null;
            bool   sslEnabled          = false;
            int    portNum             = 0;
            string strDID              = string.Empty;
            int    return_email_log_id = 0;
            bool   passed_send_checks  = false;
            bool   already_sent_today  = true;
            string returnedEmail       = string.Empty;
            bool   ok_to_send          = false;
            string noEmail             = string.Empty;


            // Check to see if email already sent to user today
            if (no_duplicates_today == true)
            {
                var prior_current_day_log = qCom_EmailLog.CheckForEmailSentLastDay(address);

                if (prior_current_day_log == null)
                {
                    already_sent_today = false;
                }
            }
            else
            {
                already_sent_today = false;
            }

            qCom_UserPreference_View u_pref = new qCom_UserPreference_View(address);

            if (u_pref.UserID > 0)
            {
                if (u_pref.OkBulkEmail == "Yes" || u_pref.OkEmail == "Yes")
                {
                    ok_to_send = true;
                }
            }
            else
            {
                ok_to_send = true;
            }

            if (already_sent_today == false && ok_to_send == true)
            {
                passed_send_checks = true;
            }
            else
            {
                passed_send_checks = false;
            }

            qPtl_User user = new qPtl_User(Convert.ToInt32(userID));

            if (user.UserID == 0)
            {
                user.Email     = "";
                user.FirstName = "";
                user.LastName  = "";
            }

            // load default email preferences
            if (String.IsNullOrEmpty(emailServer))
            {
                var email_pref = qCom_EmailPreference.GetEmailPreferences();

                if (email_pref != null)
                {
                    if (email_pref.EmailPreferencesID > 0)
                    {
                        header        = email_pref.Header;
                        footer        = email_pref.Footer;
                        strFromEmail  = email_pref.FromEmailAddress;
                        fromName      = email_pref.FromName;
                        emailServer   = email_pref.SMTPServer;
                        emailUsername = email_pref.SMTPUsername;
                        emailPassword = email_pref.SMTPPassword;
                        sslEnabled    = email_pref.SMTPSSL;
                        portNum       = email_pref.SMTPPort;
                    }
                }
            }

            // format as friendly send address
            string strFullEmail = string.Empty;

            if (!String.IsNullOrEmpty(fromName))
            {
                strFullEmail = fromName + " <" + strFromEmail + ">";
            }
            else
            {
                strFullEmail = strFromEmail;
            }

            string messageBody = header;

            messageBody += email.emailDraft;
            emailSubject = email.emailSubject;

            messageBody += footer;

            if (!String.IsNullOrEmpty(emailServer) && passed_send_checks == true)
            {
                SmtpClient emailClient = new SmtpClient(emailServer, portNum);
                emailClient.EnableSsl      = sslEnabled;
                emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                emailClient.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);

                Regex emailCheck = new Regex("^.*<?[-a-zA-Z0-9!#$%&'*+/=?^_`{|}~]+(\\.[-a-zA-Z0-9!#$%&'*+/=?^_`{|}~]+)*@(([a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9]+)?){1,63}\\.)+([a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9]+)?){2,63}>?$");

                // create temp bulk email log -- used for tracking (must be created before sent so can include id in message html)
                int t_log_id = 0;
                qCom_TempBulkEmailLog t_log = new qCom_TempBulkEmailLog();
                t_log.EmailItemID  = emailID;
                t_log.EmailAddress = strFullEmail;
                t_log.Timestamp    = DateTime.Now;
                t_log.Insert();
                t_log_id = t_log.TempBulkEmailLogID;

                if (emailCheck.IsMatch(address.ToLower()))
                {
                    string finalBody = parseContentField(new string[] { Convert.ToString(user.UserID), userName, user.FirstName, user.LastName, user.Email, DateTime.Now.ToString(), value1, value2, value3, value4, strDID, Convert.ToString(emailID), Convert.ToString(t_log_id) }, messageBody);

                    string finalSubject = parseContentField(new string[] { Convert.ToString(user.UserID), userName, user.FirstName, user.LastName, user.Email, DateTime.Now.ToString(), value1, value2, value3, value4, strDID, Convert.ToString(emailID), Convert.ToString(t_log_id) }, emailSubject);

                    MailMessage mailout = new MailMessage(strFullEmail, address, finalSubject, finalBody);
                    mailout.IsBodyHtml = true;

                    emailClient.Send(mailout);

                    return_email_log_id = AddTransmissionLog(scopeID, address, userID, "single", finalSubject, emailID, full_email.CampaignID, strFromEmail);
                }
            }

            return(return_email_log_id);
        }
        //Send to just one address with text replacement
        public int SendDatabaseMail(string address, int emailID, int userID, string userName, string value1, string value2, string value3, string value4, bool no_duplicates_today)
        {
            // get email info
            qCom_EmailTool email = new qCom_EmailTool(emailID);
            qCom_EmailItem full_email = new qCom_EmailItem(emailID);

            string header = string.Empty;
            string footer = string.Empty;
            string strFromEmail = string.Empty;
            string fromName = string.Empty;
            string emailUsername = null;
            string emailPassword = null;
            string emailServer = null;
            bool sslEnabled = false;
            int portNum = 0;
            string strDID = string.Empty;
            int return_email_log_id = 0;
            bool passed_send_checks = false;
            bool already_sent_today = true;
            string returnedEmail = string.Empty;
            bool ok_to_send = false;
            string noEmail = string.Empty;

            // Check to see if email already sent to user today
            if (no_duplicates_today == true)
            {
                var prior_current_day_log = qCom_EmailLog.CheckForEmailSentLastDay(address);

                if (prior_current_day_log == null)
                {
                    already_sent_today = false;
                }
            }
            else
            {
                already_sent_today = false;
            }

            qCom_UserPreference_View u_pref = new qCom_UserPreference_View(address);
            if (u_pref.UserID > 0)
            {
                if (u_pref.OkBulkEmail == "Yes" || u_pref.OkEmail == "Yes")
                {
                    ok_to_send = true;
                }
            }
            else
                ok_to_send = true;

            if (already_sent_today == false && ok_to_send == true)
                passed_send_checks = true;
            else
                passed_send_checks = false;

            qPtl_User user = new qPtl_User(Convert.ToInt32(userID));
            if (user.UserID == 0)
            {
                user.Email = "";
                user.FirstName = "";
                user.LastName = "";
            }

            // load default email preferences
            if (String.IsNullOrEmpty(emailServer))
            {
                var email_pref = qCom_EmailPreference.GetEmailPreferences();

                if (email_pref != null)
                {
                    if (email_pref.EmailPreferencesID > 0)
                    {
                        header = email_pref.Header;
                        footer = email_pref.Footer;
                        strFromEmail = email_pref.FromEmailAddress;
                        fromName = email_pref.FromName;
                        emailServer = email_pref.SMTPServer;
                        emailUsername = email_pref.SMTPUsername;
                        emailPassword = email_pref.SMTPPassword;
                        sslEnabled = email_pref.SMTPSSL;
                        portNum = email_pref.SMTPPort;
                    }
                }
            }

            // format as friendly send address
            string strFullEmail = string.Empty;
            if (!String.IsNullOrEmpty(fromName))
                strFullEmail = fromName + " <" + strFromEmail + ">";
            else
                strFullEmail = strFromEmail;

            string messageBody = header;

            messageBody += email.emailDraft;
            emailSubject = email.emailSubject;

            messageBody += footer;

            if (!String.IsNullOrEmpty(emailServer) && passed_send_checks == true)
            {
                SmtpClient emailClient = new SmtpClient(emailServer, portNum);
                emailClient.EnableSsl = sslEnabled;
                emailClient.DeliveryMethod = SmtpDeliveryMethod.Network;

                emailClient.Credentials = new System.Net.NetworkCredential(emailUsername, emailPassword);

                Regex emailCheck = new Regex("^.*<?[-a-zA-Z0-9!#$%&'*+/=?^_`{|}~]+(\\.[-a-zA-Z0-9!#$%&'*+/=?^_`{|}~]+)*@(([a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9]+)?){1,63}\\.)+([a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9]+)?){2,63}>?$");

                // create temp bulk email log -- used for tracking (must be created before sent so can include id in message html)
                int t_log_id = 0;
                qCom_TempBulkEmailLog t_log = new qCom_TempBulkEmailLog();
                t_log.EmailItemID = emailID;
                t_log.EmailAddress = strFullEmail;
                t_log.Timestamp = DateTime.Now;
                t_log.Insert();
                t_log_id = t_log.TempBulkEmailLogID;

                if (emailCheck.IsMatch(address.ToLower()))
                {
                    string finalBody = parseContentField(new string[] { Convert.ToString(user.UserID), userName, user.FirstName, user.LastName, user.Email, DateTime.Now.ToString(), value1, value2, value3, value4, strDID, Convert.ToString(emailID), Convert.ToString(t_log_id) }, messageBody);

                    string finalSubject = parseContentField(new string[] { Convert.ToString(user.UserID), userName, user.FirstName, user.LastName, user.Email, DateTime.Now.ToString(), value1, value2, value3, value4, strDID, Convert.ToString(emailID), Convert.ToString(t_log_id) }, emailSubject);

                    MailMessage mailout = new MailMessage(strFullEmail, address, finalSubject, finalBody);
                    mailout.IsBodyHtml = true;

                    emailClient.Send(mailout);

                    return_email_log_id = AddTransmissionLog(scopeID, address, userID, "single", finalSubject, emailID, full_email.CampaignID, strFromEmail);
                }
            }

            return return_email_log_id;
        }