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.
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
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
is working on a reply...
This forum is in read-only mode while we transition to the new forum.
You can continue this topic on the new forum by tapping the "Continue discussion" link below.