示例#1
0
        private static int Send_Usage_Emails(int year, int month, string SystemUrl, string SystemName, string FromAddress, string FromName)
        {
            // Get the list of all users linked to items
            DataTable usersLinkedToItems = Engine_Database.Get_Users_Linked_To_Items(null);

            // If NULL, then no data linked to users
            if (usersLinkedToItems == null)
            {
                return(0);
            }

            // Determine the FROM
            string fromAddr = FromAddress;

            if (!String.IsNullOrEmpty(FromName))
            {
                fromAddr = FromName + " <" + FromAddress + ">";
            }

            // Step through each row and pull data about the usage stats for this user
            int emails_sent = 0;

            foreach (DataRow thisRow in usersLinkedToItems.Rows)
            {
                Thread.Sleep(1000);

                // Pull out the user information from this row
                string firstName = thisRow[0].ToString();
                string lastName  = thisRow[1].ToString();
                string nickName  = thisRow[2].ToString();
                int    userid    = Convert.ToInt32(thisRow[4]);
                string email     = thisRow[5].ToString();

                // Compose the name
                string name = firstName + " " + lastName;
                if (nickName.Length > 0)
                {
                    name = nickName + " " + lastName;
                }

                // Try to compose and send the email.  The email will only be sent if there was
                // some total usage this month, as well as total
                if (Usage_Stats_Email_Helper.Send_Individual_Usage_Email(userid, name, email, year, month, 10, SystemUrl, SystemName, fromAddr))
                {
                    emails_sent++;
                }
            }

            return(emails_sent);
        }