Wrox Programmer Forums

Need to download code?

View our list of code downloads.

| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 19th, 2008, 06:21 AM
Authorized User
 
Join Date: Mar 2008
Location: , , .
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="mytest@mydomain.com,newuser@mydomain.co.uk " mailCC="addme@mydomain.co.uk,addme@newdomain.com"/>

  #2 (permalink)  
Old May 20th, 2008, 12:43 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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).

  #3 (permalink)  
Old May 20th, 2008, 07:56 AM
Authorized User
 
Join Date: Mar 2008
Location: , , .
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="first.address@domain.co.uk, second.address@domain.co.uk"/>

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



  #4 (permalink)  
Old May 20th, 2008, 02:11 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
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;
            }
        }
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 02:15 PM.


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