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 4 : in C# and VB
This is the forum to discuss the Wrox book Beginning ASP.NET 4: in C# and VB by Imar Spaanjaars; ISBN: 9780470502211
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning ASP.NET 4 : in C# and VB 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
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 31st, 2012, 02:25 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default SMTP question

Quick question: I noticed in chapter 9 and 10 of your book that you have the email addresses hard coded in the Web.config files and in the .ascx.cs page of the the contact form. Is there anyway at all that these email addresses in both the web.config and the in the code behind of the contact.ascx form can be created dynamically without having to be hard coded into the forms and web.config files themselves.

Thank you once again.
Reply With Quote
  #2 (permalink)  
Old January 31st, 2012, 03:56 PM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,014
Thanks: 79
Thanked 1,577 Times in 1,554 Posts
Default

Hi there,

What do you mean with this:

Quote:
can be created dynamically without having to be hard coded into the forms and web.config files themselves.
You need to store the addresses somewhere, no?

Chapter 19 shows how to move the addresses from the Code Behind into the web.config so you have a central location to manage them.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #3 (permalink)  
Old January 31st, 2012, 04:15 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default

Quote:
Originally Posted by Imar View Post
Hi there,

What do you mean with this:


You need to store the addresses somewhere, no?

Chapter 19 shows how to move the addresses from the Code Behind into the web.config so you have a central location to manage them.

Cheers,

Imar
[code]
I am sorry I should have been more specific. In your web.config file you have the following stuff:
For example:
<mailSettings>
<smtp deliveryMethod="Network" from="Joe@aol.com">
<network enableSsl="true" userName="Joe@aol.com" password="123ABC" host="smtp.aol.com" port="587"/>
<specifiedPickupDirectory pickupDirectoryLocation="C:\TempMail" />
</smtp>
</mailSettings>
Then .cs file of the contactform.ascx you have:
myMessage.From = new MailAddress("Joe@aol.com", "Joe Norrigan");
myMessage.To.Add(new MailAddress("LoriL@yahoo.com", "Lori Lopez"));

As you can see up above the email addresses are all hard coded into the web.config file and the code behind of the .ascx file. Is there anyway that the information for the webaddresses not be hard coded into those files or a central location, but are instead created dynamically on the fly, by the user typing the information into a textbox or a text area instead of them being stored in a different centralized location? I hope that helps me clarify things just a little bit better.

As always: Thanks again!
Reply With Quote
  #4 (permalink)  
Old January 31st, 2012, 04:26 PM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,014
Thanks: 79
Thanked 1,577 Times in 1,554 Posts
Default

Sure. Just replace this:

Code:
myMessage.From = new MailAddress("Joe@aol.com", "Joe Norrigan");
with this:

Code:
myMessage.From = new MailAddress(txtEmailAddress.Text, txtEmailName.Text);
You can't programmatically override the from in the smtp settings, but it only serves as a default. By setting the From in code as shown above, the from in the web.config is not used.

I personally don't like this though. When an e-mail address is not valid, your e-mail may not get sent correctly. It also creates opportunities for spammers / hackers to send e-mails out of someone else's name.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #5 (permalink)  
Old January 31st, 2012, 04:28 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default SMTP Question

[code]

I guess in other words what I am trying to say is there anyway that a user can type in a text box their email address and then put that into the code instead? The example in the book is hard coded, is:
Message.from = new.MailAddress("you@yourprovider.com, "Sender Name");
Message.To.Add(new MailAddress("you@yourprovider.com,"Receiver Name");
Would it be possible to enter the sender and receiver information into a textbox or textarea and then put them into the "you@yourprovider.com", Receivername) dynamically inside the code. Because I don't see where the text information off of the webform is being subsitituted into the to segment of the address up above. Maybe it is just me. Maybe I am just confused. I just don't see how the email address in the text box is being substituted into the code example up above.
Reply With Quote
  #6 (permalink)  
Old January 31st, 2012, 05:57 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default SMTP question

Quote:
Originally Posted by Imar View Post
Sure. Just replace this:

Code:
myMessage.From = new MailAddress("Joe@aol.com", "Joe Norrigan");
with this:

Code:
myMessage.From = new MailAddress(txtEmailAddress.Text, txtEmailName.Text);
You can't programmatically override the from in the smtp settings, but it only serves as a default. By setting the From in code as shown above, the from in the web.config is not used.

I personally don't like this though. When an e-mail address is not valid, your e-mail may not get sent correctly. It also creates opportunities for spammers / hackers to send e-mails out of someone else's name.

Cheers,

Imar
Code:
What I was kind of actually wondering about was the To: address. As I am sure you are aware, (and please correct me if I am wrong) the To:adress is hard coded into the ascx.cs file with the following line of code:
myMessage.To.Add(new MailAddress("youraddress@yourprovider.com", "Receiver Name"));
That then beggars the hypothetical question of: lets just say for instance I am Greg Norigan with an email address of GregN@aol.com and I go to your website of ImarProductions.com to sign up for your email newsletter that has all the latest, up to date information about concert dates, concert reviews, new musical CD releases etc, etc, and I put my name and email address in the textboxes and then the "to:" field of the email address is hardcoded to go to Lori Lopez with an email address at LoriL@aol.com, inside the ascx.cs file then how is that beneficial to you and your website? The email then gets sent to LoriL@aol.com instead of GregN@aol.com does it not? This is where my confusion basically comes from. That is what I really don't understand.
Reply With Quote
  #7 (permalink)  
Old January 31st, 2012, 06:16 PM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,014
Thanks: 79
Thanked 1,577 Times in 1,554 Posts
Default

First of all, you can do the same thing with the To address to make it dynamic.

But obviously it all depends who the target of the e-mail is. In the book's example, it's a contact form so it makes a lot of sense to send this to the site's owner / manager and not to the person sending the message (as he would be talking to himself).

For a newsletter you do indeed need the user's address. If you send out the information right away, just take the To from the form. For regular newsletters, you typically store the addresses in a database and use them in the To field when you send out the newsletter.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
Reply With Quote
  #8 (permalink)  
Old January 31st, 2012, 08:36 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default SMTP Question

Quote:
Originally Posted by Imar View Post
First of all, you can do the same thing with the To address to make it dynamic.

But obviously it all depends who the target of the e-mail is. In the book's example, it's a contact form so it makes a lot of sense to send this to the site's owner / manager and not to the person sending the message (as he would be talking to himself).

For a newsletter you do indeed need the user's address. If you send out the information right away, just take the To from the form. For regular newsletters, you typically store the addresses in a database and use them in the To field when you send out the newsletter.

Cheers,

Imar
All I can say is it would have been nice if you had included in your book how to do newsletters using ASP.NET 4.0 and SQL Server.
Reply With Quote
  #9 (permalink)  
Old February 1st, 2012, 07:05 AM
Imar's Avatar
Wrox Author
Points: 71,632, Level: 100
Points: 71,632, Level: 100 Points: 71,632, Level: 100 Points: 71,632, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,014
Thanks: 79
Thanked 1,577 Times in 1,554 Posts
Default

Quote:
All I can say is it would have been nice if you had included in your book how to do newsletters
That's not a whole lot ;-)

The thing is: there are potentially hundreds of other topics I haven't been able to cover. I already had troubles keeping the book under 800 pages. Also, building a Newsletter tool is not a small undertaking and is probably better off in the follow up Pro edition of this book.

That all said, you'll find all the information in the book to build this yourself. Storing and retrieving data from a database is covered extensively (e.g. Signup and sending out the newsletters). The chapter on mail shows how to send out e-mails and the chapter on deployment shows how to make the addresses dynamic (just as I showed in this thread). Adding it all together would give you a good start to newsletter type of functionality.

I am in the process of updating the book for the next version of .NET, so if you absolutely think newsletters is a topic that should be covered, feel free to post a list of topics that you'd like to see covered.

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!

Last edited by Imar; February 1st, 2012 at 07:29 AM.
Reply With Quote
  #10 (permalink)  
Old February 1st, 2012, 01:02 PM
Friend of Wrox
Points: 1,905, Level: 17
Points: 1,905, Level: 17 Points: 1,905, Level: 17 Points: 1,905, Level: 17
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Posts: 411
Thanks: 13
Thanked 7 Times in 7 Posts
Default

Quote:
Originally Posted by Imar View Post
That's not a whole lot ;-)

I am in the process of updating the book for the next version of .NET, so if you absolutely think newsletters is a topic that should be covered, feel free to post a list of topics that you'd like to see covered.

Cheers,

Imar
Just curious......
So you say there is a new version of .NET in the works? Any time table for a possible release date that you might be aware of? Is there a beta version already available?

Thanks once again.
Reply With Quote
Reply


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
SMTP Email question snufse ASP.NET 2.0 Basics 2 July 9th, 2009 11:08 AM
Smtp teddyk ASP.NET 2.0 Basics 5 November 1st, 2008 03:46 PM
SMTP problem hastikeyvan ASP.NET 2.0 Professional 3 August 10th, 2006 01:40 AM
Help on C#/SMTP peri C# 2 December 6th, 2004 09:43 PM
About SMTP abdul_owiusa C# 2 August 6th, 2004 06:12 AM



All times are GMT -4. The time now is 07:37 PM.


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