Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8
This is the forum to discuss the Wrox book Beginning ASP.NET 2.0 by Chris Hart, John Kauffman, David Sussman, Chris Ullman; ISBN: 9780764588501
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 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 Display Modes
  #1 (permalink)  
Old January 9th, 2008, 11:46 AM
Authorized User
 
Join Date: May 2007
Location: , , United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 c# version, system.net query

In Chapter 2 - 'Site Design', page 49 it says you can add <system.net> <mailSettings> etc. into the web config file to declare the SMTP.

<system.net>
        <mailSettings>
          <smtp from="admin@your-domain.com">
            <network host="your-mail-server-name"
              userName="your-user-name"
              password="your-password"/>"

          </smtp>
        </mailSettings>
      </system.net>

I have added this as is written in the book complete with closing tags but I am getting errors saying it is an invalid child element and an unrecognized configuration section element. I am using VWD 2005 Express.

Why is this??
Many thanks
Jude

  #2 (permalink)  
Old January 9th, 2008, 01:40 PM
Authorized User
 
Join Date: Dec 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Doug Happ
Default

Jude,
I'm not sure that I can be of any help since I am a real neophyte at this stuff. I'm also on chapter 2.

1. Are we talking about the same book; I do not have that code on page 49. In my book on page 47 there is a topic of "General Guidelines for Site design", but nothing as specific as the text you quoted. My book is Beginning ASP.NET 2.0 Copyright 2006

2. In looking at your code, should it be <system.web>, not <system.net>???

Doug Happ
When the eagle is away, the crow says "I am the eagle."
  #3 (permalink)  
Old January 10th, 2008, 08:56 AM
Authorized User
 
Join Date: May 2007
Location: , , United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Doug

Thanks for the input..I too am completely new to this - my book is 'Beginning ASp.NET 2.0 with C#' copyright 2006.

I thought the code had to be <system.web> too, but this section on page 49 gives an example with the <system.net> tags enclosed within <system.web>. It's in the section 'Site Design'.

One of the things that frustrates me as a web designer- about the book is,there are no examples of how to create a email feedback form and how to use the mail class. Apart from the above mention which does not work!

Online some examples uses system.net...yet in VWD 2005 Express it reads system.web. Confusing.

any advice appreciated,

J
  #4 (permalink)  
Old January 10th, 2008, 09:03 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hello everyone.  Here is how your web.config should break down:
<?xml version='1.0' encoding='utf-8' ?>
<configuration>
  <system.web>

  </system.web>
  <system.net>
        <mailSettings>
          <smtp from="admin@your-domain.com">
            <network host="your-mail-server-name"
              userName="your-user-name"
              password="your-password"/>"

          </smtp>
        </mailSettings>
    </system.net>
</configuration>
hth.


================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
  #5 (permalink)  
Old January 10th, 2008, 09:08 AM
Authorized User
 
Join Date: Dec 2007
Location: , , .
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to Doug Happ
Default

J,
After I suggested using .web I did a little looking and realized that the .net is the appropriate extension.

The reason our books seem different is that you are using C# and I'm using VB.

Have you tried using the ASP.NET Configure tool (also known as the Web Site Administration Tool) to set the email settings?

Doug Happ
When the eagle is away, the crow says "I am the eagle."
  #6 (permalink)  
Old January 10th, 2008, 10:42 AM
Authorized User
 
Join Date: May 2007
Location: , , United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

DP This is nested correctly now thanks - no errors. Can you tell me - is this the right way to go about sending a simple email feedback form? What else do I need to add??

Doug - I will look into using the web admin tool, not sure what it does. I really just want to be able to send a simple email feedback form to an email address...I seem to be floundering in many ways to do this and can get none to work,

Many thanks for the advice
J
  #7 (permalink)  
Old January 10th, 2008, 10:50 AM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Hmmm.  I am not quite sure, I pulled that code out of a web.config for a currently running application. Strange.

Here is an example mailer that uses the mail class directly and does not rely on the web.config for its settings:

string message = "Just a test email body";
//Define your SMTP host
SmptClient client = new SmtpClient();
client.Host = "localhost";

MailMessage msg = new MailMessage("<from address>", "<to address>");
msg.Subject = "Foo";
msg.Body = message;
client.Send(msg);


Also, could you post your entire web.config so I can see it?

hth.

-Doug

P.S.
If you wanted to add credentials to log onto the server you would do something like this:
client.Credentials = new NetworkCredntial("<user>", "<pass>");

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
  #8 (permalink)  
Old January 11th, 2008, 09:59 AM
Authorized User
 
Join Date: May 2007
Location: , , United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi
the web config is nested correctly codewise now - thanks Doug.

Can you explain the reasoning behind having to put these settings in the web.config file when using online...is it for authentication for the relay server? Are the username and password the same as they are for my domain??

Many thanks for any pointers
J



  #9 (permalink)  
Old January 11th, 2008, 01:43 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

Sure.

Consider the code I provided in my last post:
string message = "Just a test email body";
//Define your SMTP host
SmptClient client = new SmtpClient();
client.Host = "localhost";

MailMessage msg = new MailMessage("<from address>", "<to address>");
msg.Subject = "Foo";
msg.Body = message;
client.Send(msg);

Now say that you had 6 different webforms that used this code but then you get a requirement that the Email Server Addressed has changed, you are going to have to go back to each of those 6 pages and change the Host property to the new Email Server.

To remedy this you could create a class and place a method in it like this:

public static void SendEmail()
{
string message = "Just a test email body";
//Define your SMTP host
SmptClient client = new SmtpClient();
client.Host = "localhost";

MailMessage msg = new MailMessage("<from address>", "<to address>");
msg.Subject = "Foo";
msg.Body = message;
client.Send(msg);
}

And then you could just make a call on all 6 of your Webforms like this: MyClass.SendEmail(). So using the secnario from earlier you now only would have to change the Host Field in one place which is much more effecient but this code isn't portable because you have physically tied the code to your Email Server!

So, by placing the values of your email server in the web.config you do not need to explictly define the address of the server in your code since they will be pulled from the web.config. By doing this you could take that code and drop it into any website, configure the values in the web.config and you are done.

Lastly, regarding Authentication and relaying, some servers require authentication to connect to the SMTP service (for example if you wanted to send mail through GMail, you need to provide your Gmail username and password before you can pass mail through their SMTP).

However, in the case of the Virtual SMTP server that runs with IIS there is no authentication information required, however, to enable relaying you have to configure the SMTP to allow it to relay messages from your machine.

hth.

================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========
  #10 (permalink)  
Old January 16th, 2008, 08:57 AM
Authorized User
 
Join Date: May 2007
Location: , , United Kingdom.
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Doug for the explanation
I understand how it works a lot better now :)

I have tried the code however and there are still errors coming up - is this how it should be? (using VWD 2005 Express - see below)

thanks, J

using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        public static void SendEmail()
{
string message = "Just a test email body";
//Define your SMTP host
SmptClient client = new SmtpClient();
client.Host = "localhost";

MailMessage msg = new MailMessage("<from address>", "<to address>");
msg.Subject = "Foo";
msg.Body = message;
client.Send(msg);
}

    }

}
 


Thread Tools
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
Chapter 13 C# Version getting error with class Craig07 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 February 14th, 2008 06:52 PM
Chapter 7 download file missing , C# version Judy BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 2 September 11th, 2007 10:06 AM
Database error in Chapter 13, C# version Judy BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 July 25th, 2007 10:30 AM
Chapter 13 VB Version michaelcode BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 1 August 10th, 2006 11:07 AM
Import SQL 2K query into SQLServer under version toantvo SQL Server 2000 3 September 3rd, 2004 09:41 AM



All times are GMT -4. The time now is 11:53 PM.


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