public bool SendInvite(string to, string from, Invite invite)
        {
            string[] emailTo = new string[] { to };

            Dictionary<string, string> replaceVars = new Dictionary<string, string>();
            replaceVars.Add("FIRST_NAME", invite.FirstName);

            return SendEmail(emailTo, from, EMAIL_TEMPLATES.INVITE_BASIC, replaceVars);
        }
        private void sendEmailsOld(List<EmailCampaign> emailsToSend)
        {
            int emailsSent = 0;
            foreach(AccountCampaign acc in _campaign.AccountCampaigns)
            {
                int emailsAvailable = getEmailAvailableCount(acc.Account);
                if (emailsAvailable <= 0) { break; }

                EmailLib.EmailManager emailManager = new EmailManager(getGoogleEmailConfig(acc.Account.UserName, acc.Account.Password));
                while (emailsAvailable > 0 && emailsToSend.Count > 0)
                {
                    EmailCampaign emailToSend = emailsToSend.First();
                    Invite emailInvite = new Invite() { FirstName = emailToSend.Email.FirstName };
                    bool status = emailManager.SendInvite(emailToSend.Email.Address, acc.Account.UserName, emailInvite);
                    if (status)
                    {
                        emailToSend.StatusID = (int)EmailStatusID.Sent;
                        _musubiRepo.UpdateEmail(emailToSend.Email); //TODO: FIX
                    }
                    emailsAvailable++;
                    emailsSent++;
                    log("Emails Sent = " + emailsSent);
                    _musubiRepo.UpdateAccountActivity(acc.Account, emailsSent);
                    emailsToSend.Remove(emailToSend);
                }
            }
        }
        private void btnSendAll_Click(object sender, RoutedEventArgs e)
        {
            Random rand = new Random();
            int emailsAvailable = getEmailsAvailableForCampaign();
            List<EmailCampaign> emailsToSend = _campaign.EmailCampaigns.Take(emailsAvailable).ToList();

            int numAccounts = _campaign.AccountCampaigns.Count - 1;
            List<AccountCampaign> accountCampaigns = _campaign.AccountCampaigns.ToList();

            int emailsSent = 0;
            int accountCounter = 0;
            foreach (EmailCampaign emailToSend in emailsToSend)
            {
                AccountCampaign acc = accountCampaigns[accountCounter];
                if (accountCounter <= (numAccounts - 1)) { accountCounter++; }
                else { accountCounter = 0; }
                EmailLib.EmailManager emailManager = new EmailManager(getGoogleEmailConfig(acc.Account.UserName, acc.Account.Password));

                bool slipsumTrigger = (rand.Next(12) == 1);
                if (!slipsumTrigger)
                {
                    Invite emailInvite = new Invite() { FirstName = emailToSend.Email.FirstName };
                    try
                    {
                        //bool status = false;
                        bool status = emailManager.SendRandomInvite(emailToSend.Email.Address, acc.Account.UserName, emailInvite);
                        //if (emailsSent == 3) throw new Exception("derp");
                        if (status)
                        {
                            emailToSend.StatusID = (int)EmailStatusID.Sent;
                            _musubiRepo.UpdateEmail(emailToSend.Email); //TODO: FIX
                        }
                        else { log("FAILED TO SEND EMAIL"); }
                    }
                    catch (Exception ex)
                    {
                        accountCampaigns.Remove(acc);
                        numAccounts--;
                        log(String.Format("{0} failed", emailToSend.Email.Address));
                    }
                    log(String.Format("Sending REGULAR email to {0}, from {1}", emailToSend.Email.Address, acc.Account.UserName));
                    acc.Account.ActivityCount++;
                    emailsSent++;
                }
                else
                {
                    Slipsum slipsum = new Slipsum();
                    string[] slipsum_address = { "*****@*****.**", "*****@*****.**", "[email protected], [email protected]"};
                    int slipsumIndex = rand.Next(slipsum_address.Length - 1);
                    string slipsumTo = slipsum_address[slipsumIndex];

                    //emailManager.SendSlipsum(slipsumTo, acc.Account.UserName, slipsum.Generate(1), slipsum.Generate(5));
                    log(String.Format("Sending Slipsum email to {0}, from {1}", slipsumTo, acc.Account.UserName));
                }

                log("Emails Sent = " + emailsSent);
                System.Threading.Thread.Sleep(1000 * 60 * 2);
            }

            foreach (AccountCampaign acc in _campaign.AccountCampaigns)
            {
                _musubiRepo.UpdateAccountActivity(acc.Account, acc.Account.ActivityCount);
            }
        }
        public bool SendRandomInvite(string to, string from, Invite invite)
        {
            string[] emailTo = new string[] { to };
            int templatesCount = EMAIL_INVITE_TEMPLATES.Length - 1;
            int index = new Random().Next(templatesCount);
            string inviteTemplate = EMAIL_INVITE_TEMPLATES[index];

            Dictionary<string, string> replaceVars = new Dictionary<string, string>();
            replaceVars.Add("FIRST_NAME", invite.FirstName);

            return SendEmail(emailTo, from, inviteTemplate, replaceVars);
            //return false;
        }