Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    May 24, 2011 @ 15:51
    Bjarne Fyrstenborg
    0

    Send mail to custom group

    Hi

    I have created a custom tree in a new section in Umbraco backend from where my client shall be able to select between the subscribed to the newsletter.

    The link is a simple <a href="mailto: " + subscribers; where I need the selected group from the dropdown to be saved as a string.

    E.g: the dropdown gets the categories from a database table titel (everybody, coach, parents, etc. ). All subscribers are saved in another database table nyhedsTilmelding, where there is a column for the title/category. When Everybody (Alle) is selected to mailto link need all the subscribers e-mails, when Coach (træner) is seleted the mailto link need to get the e-mails where the title is Coach (træner) in the database table.

    - Bjarne

  • Bjarne Fyrstenborg 1282 posts 3994 karma points MVP 8x c-trib
    May 26, 2011 @ 21:04
    Bjarne Fyrstenborg
    0

    Well, i found a solution myself.

    string connectionString = WebConfigurationManager.ConnectionStrings["umbracoConnectionString"].ConnectionString;
    SqlConnection conn = new SqlConnection(connectionString);SqlCommand cmdGroup = new SqlCommand("SELECT Email FROM nyhedsTilmelding WHERE Titel=@Titel", conn);
    SqlCommand cmdAll = new SqlCommand("SELECT Email FROM nyhedsTilmelding", conn);
    
    cmdGroup.Parameters.Add("@Titel", System.Data.SqlDbType.NVarChar, 50);
    cmdGroup.Parameters["@Titel"].Value = CategoryDropDownList.SelectedValue;
    
    if (CategoryDropDownList.SelectedValue == "Alle")
    {
        cmdAll.Connection.Open();
            SqlDataReader rdr = cmdAll.ExecuteReader();
            if (rdr.HasRows)
            {
                List<string> emailAll = new List<string>();
                    while (rdr.Read())
                    {
                        emailAll.Add(rdr["Email"].ToString());
                            emailAll.Distinct().ToList();
                    }
                    string strEmailAll = string.Join(", ", emailAll.ToArray());
                    SendButton.NavigateUrl = "mailto:?subject=Nyhedsmail fra Oldengard.dk&bcc=" + strEmailAll;
                    rdr.Close();
                    cmdAll.Connection.Close();
                    cmdAll.Connection.Dispose();
        }
            else
            {
                SendButton.NavigateUrl = "mailto:"; //just empty link with mailto, could remove the link instead
            }
    }
    else
    {
        cmdGroup.Connection.Open();
            SqlDataReader reader = cmdGroup.ExecuteReader();
            if (reader.HasRows)
            {
                List<string> emailGroup = new List<string>();
                while (reader.Read())
                    {
                        emailGroup.Add(reader["Email"].ToString());
                            emailGroup.Distinct().ToList();
                    }
                    string strEmailGroup = string.Join(", ", emailGroup.ToArray());
                    SendButton.NavigateUrl = "mailto:?subject=Nyhedsmail fra Oldengard.dk&bcc=" + strEmailGroup;
                    reader.Close();
                    cmdGroup.Connection.Close();
                cmdGroup.Connection.Dispose();
            }
        else
            {
                SendButton.NavigateUrl = "mailto:"; //just empty link with mailto, could remove the link instead
    } }

    - Bjarne

Please Sign in or register to post replies

Write your reply to:

Draft