Beispiel #1
0
        /// <summary>
        /// This will take a list of email addresses, format them and put them into the selected field.  This will overwrite any values currently
        /// in that field.
        /// </summary>
        /// <param name="fieldToPopulate"></param>
        /// <param name="values"></param>
        public void PopulateAddressString(PopulateTypes fieldToPopulate, List <string> values)
        {
            var sb = new StringBuilder();

            foreach (string buf in values)
            {
                sb.AppendFormat("{0};", buf);
            }

            switch (fieldToPopulate)
            {
            case PopulateTypes.To:
                this.To = sb.ToString().Trim(";");

                break;

            case PopulateTypes.Bcc:
                this.Bcc = sb.ToString().Trim(";");

                break;

            case PopulateTypes.Cc:
                this.Cc = sb.ToString().Trim(";");

                break;
            }
        }
Beispiel #2
0
 /// <summary>
 /// This will take a list of email addresses, format them and put them into the selected field.  If the selected entry is a username
 /// and not an email address, this will attempt to cross reference a user table given the required database connection and sql statement.
 /// The SQL statement must return to fields, "username" and "email".. e.g. select username, email from web_users.  If an email address isn't
 /// found for a username, it will be excluded from the send list.  The database connection must already be initialized and open, this sub
 /// also won't close it so you must close and dispose of it on your own.
 /// </summary>
 /// <param name="fieldToPopulate"></param>
 /// <param name="values"></param>
 public void PopulateAddressString(PopulateTypes fieldToPopulate, string[] values, IDbConnection conn, string sql)
 {
     this.PopulateAddressString(fieldToPopulate, values.ToList(), conn, sql);
 }
Beispiel #3
0
        /// <summary>
        /// This will take a list of email addresses, format them and put them into the selected field.  If the selected entry is a username
        /// and not an email address, this will attempt to cross reference a user table given the required database connection and sql statement.
        /// The SQL statement must return to fields, "username" and "email".. e.g. select username, email from web_users.  If an email address isn't
        /// found for a username, it will be excluded from the send list.  The database connection must already be initialized and open, this sub
        /// also won't close it so you must close and dispose of it on your own.
        /// </summary>
        /// <param name="fieldToPopulate"></param>
        /// <param name="values"></param>
        public void PopulateAddressString(PopulateTypes fieldToPopulate, List <string> values, IDbConnection conn, string sql)
        {
            if (conn == null)
            {
                throw new Exception("Database connection was null.");
            }

            if (conn.State != ConnectionState.Open)
            {
                throw new Exception("Database connection must be open.");
            }

            var userList = new NameValueCollection();

            var command = conn.CreateCommand();

            command.CommandText = sql;
            var dr = command.ExecuteReader();

            while (dr.Read())
            {
                userList.Add(dr["username"].ToString(), dr["gmail"].ToString());
            }

            var sb = new StringBuilder();


            foreach (string buf in values)
            {
                if (buf.Contains("@"))
                {
                    // It's an e-mail, straight add it.
                    sb.AppendFormat("{0};", buf);
                }
                else
                {
                    // It's a username, attempt to look it up
                    string email = userList[buf];

                    if (string.IsNullOrEmpty(email) == false)
                    {
                        sb.AppendFormat("{0};", email);
                    }
                }
            }

            switch (fieldToPopulate)
            {
            case PopulateTypes.To:
                this.To = sb.ToString().Trim(";");

                break;

            case PopulateTypes.Bcc:
                this.Bcc = sb.ToString().Trim(";");

                break;

            case PopulateTypes.Cc:
                this.Cc = sb.ToString().Trim(";");

                break;
            }

            // Cleanup the database object we created.
            dr.Close();
            command.Dispose();
        }