Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old May 19th, 2008, 06:21 AM
Authorized User
 
Join Date: Mar 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default multiple CCs in webconfig contact forms

Having trouble sending the contact us form to multiple recipients. Any Ideas of how to add these: e.g.:


<contactForm mailTo="[email protected],[email protected] " mailCC="[email protected],[email protected]"/>

 
Old May 20th, 2008, 12:43 AM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

This should be fairly simple. You could indicate them in the web.config just as you are showing in your post.

In the contact form code, you'd could parse the Globals.Settings.ContactForm.MailTo and Globals.Settings.ContactForm.MailCC strings at the commas. Then add them to the To and CC collections using the Add method (either repeatedly or in a foreach).

 
Old May 20th, 2008, 07:56 AM
Authorized User
 
Join Date: Mar 2008
Posts: 16
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply. I tried the first changing the webconfig to:
 <contactForm mailTo="[email protected], [email protected]"/>

but the second address doesn't get sent for some reason



 
Old May 20th, 2008, 02:11 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

The following code would work, whether you had 2, 20, or 200 names in your web.config.



        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                // send the mail
                MailMessage msg = new MailMessage();
                msg.IsBodyHtml = false;
                msg.From = new MailAddress(txtEmail.Text, txtName.Text);
                string[] addressesToMailTo =
                   Globals.Settings.ContactForm.MailTo.Split((new char[] { ',', ' ' }), StringSplitOptions.RemoveEmptyEntries);
                foreach (string address in addressesToMailTo)
                   msg.To.Add(address);
                if (!string.IsNullOrEmpty(Globals.Settings.ContactFor m.MailCC))
                {
                   string[] addressesToCCTo =
                      Globals.Settings.ContactForm.MailCC.Split((new char[] { ',', ' ' }), StringSplitOptions.RemoveEmptyEntries);
                   foreach (string address in addressesToCCTo)
                      msg.CC.Add(address);
                }
                msg.Subject = string.Format(
                    Globals.Settings.ContactForm.MailSubject, txtSubject.Text);
                msg.Body = txtBody.Text;
                new SmtpClient().Send(msg);
                // show a confirmation message and reset the field
                lblFeedbackOK.Visible = true;
                lblFeedbackKO.Visible = false;
                txtName.Text = "";
                txtEmail.Text = "";
                txtSubject.Text = "";
                txtBody.Text = "";
            }
            catch (Exception)
            {
                lblFeedbackOK.Visible = false;
                lblFeedbackKO.Visible = true;
            }
        }





Similar Threads
Thread Thread Starter Forum Replies Last Post
BugBase: .CCS question rjd BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 November 21st, 2006 05:21 PM
CCS cb ASP.NET 2.0 Basics 2 October 3rd, 2006 09:58 AM
Trouble with UrlMapping in webconfig ! bananas ASP.NET 2.0 Professional 3 August 30th, 2006 12:47 AM
email contact forms xeno Beginning PHP 0 July 30th, 2005 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.