Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
Password Reminder
Register
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 April 15th, 2010, 06:03 PM
Registered User
 
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9. I can't figure how to configure my website for sending E-mail

Any way I setup gmail, yahoo or hotmail accounts for this step. I'm stuck here.
Reply With Quote
  #2 (permalink)  
Old April 15th, 2010, 06:16 PM
Imar's Avatar
Wrox Author
Points: 71,662, Level: 100
Points: 71,662, Level: 100 Points: 71,662, Level: 100 Points: 71,662, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,015
Thanks: 79
Thanked 1,578 Times in 1,555 Posts
Default

Hi there,

Can you explain where / how you're stuck exactly? The book has detailed explanations of making this work for Gmail. Can you explain what you've done so far?

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 April 15th, 2010, 08:04 PM
Registered User
 
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Imar

I just noticed, I have your Beginning ASP.NET 3.5 book.

Charpter 9, page- 309

1. I created a file called Email.aspx
2. Added the same exact code you specified to a Page_Load Handler, with the exception of my e-mail address and name.
3. In web.Config, I added the following code..

<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.gmail.com" userName="my_ID" password="my password" port="465" />

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

I get a 'timeout' error when I run the Email.aspx page.
Reply With Quote
  #4 (permalink)  
Old April 16th, 2010, 02:31 AM
Imar's Avatar
Wrox Author
Points: 71,662, Level: 100
Points: 71,662, Level: 100 Points: 71,662, Level: 100 Points: 71,662, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,015
Thanks: 79
Thanked 1,578 Times in 1,555 Posts
Default

Hi there,

Take another look at step 4 on page 320 and at the Common Mistakes box at the bottom of the page. You left out the enableSsl attribute which Gmail requires. Also, try port 587 instead of 465. This works for me:

Code:
 
<system.net>
  <mailSettings>
    <smtp deliveryMethod="Network">
      <network host="smtp.gmail.com" userName="User" password="Password" port="587" enableSsl="true" />
    </smtp>
  </mailSettings>
</system.net>
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 April 16th, 2010, 11:37 AM
Registered User
 
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Declaring EnableSsl.

Where do declare EnableSsl which you described in the above code?

PS. Page 320 in Beginning ASP.NET 3.5 is blank. Are you referring to a different book?
Reply With Quote
  #6 (permalink)  
Old April 16th, 2010, 11:43 AM
Imar's Avatar
Wrox Author
Points: 71,662, Level: 100
Points: 71,662, Level: 100 Points: 71,662, Level: 100 Points: 71,662, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,015
Thanks: 79
Thanked 1,578 Times in 1,555 Posts
Default

You have posted this in the forum for Beginning ASP.NET 4 so I assumed, silly me, you were using that book ;-)

You may want to take a look here: http://imar.spaanjaars.com/QuickDocId.aspx?QUICKDOC=505

In .NET 3.5, you manually need to create an SmtpClient and set the EnableSsl property to true as explained in that article. In .NET 4 you can do this declaratively in the web.config file.

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
  #7 (permalink)  
Old April 17th, 2010, 08:08 AM
Friend of Wrox
Points: 752, Level: 10
Points: 752, Level: 10 Points: 752, Level: 10 Points: 752, Level: 10
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
Arrow

Hi there,
for .Net 3.5 try this one

Code:
Dim mySmtpClient As New SmtpClient()
            Try
                mySmtpClient.EnableSsl = True
                mySmtpClient.Send(myMessage)
            Catch ex As Exception
                lblMessage.Text = "An Error Occurred, Please Try Again."
            End Try
The above code is in VB.NET
Hope this helps you.

Cheers,

Jack
Reply With Quote
  #8 (permalink)  
Old April 17th, 2010, 09:19 AM
Registered User
 
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Argh...I must be doing something wrong...

Imar, I followed your link and added the following code to my website

Here's my code in Email.aspx

{public partial class Email : BasePage
{

protected void Page_Load(object sender, EventArgs e)
{
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Test Message";
myMessage.Body = "Hello world, from PlanetWrox";

myMessage.From = new MailAddress("name@gmail.com", "My Name");
myMessage.To.Add(new MailAddress(""name@gmail.com", "My Name"));

SmtpClient mySmptClient = new SmtpClient();
mySmptClient.EnableSsl = true;
mySmptClient.Send(myMessage);
}
}
I added this code to web.config...

{
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="myname@gmail.com">
<network
port="587"
userName="myname@gmail.com"
password="mypassword"
host="smtp.gmail.com"/>
</smtp>
</mailSettings>
</system.net>
}

I still get the following error...

System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Reply With Quote
  #9 (permalink)  
Old April 17th, 2010, 09:50 AM
Imar's Avatar
Wrox Author
Points: 71,662, Level: 100
Points: 71,662, Level: 100 Points: 71,662, Level: 100 Points: 71,662, Level: 100
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,015
Thanks: 79
Thanked 1,578 Times in 1,555 Posts
Default

Hi there,

That's strange. I just copied your code and configuration in a new web site and it works fine for me.

A few things you could check:

1. Is this really the code that is firing? Or does your page have other (Login) controls that try to send mail on their own?

2. Are your user name and password correct?

3. Are you using the right Gmail name? You need to use myname@gmail.com; not just myname.

4. Is your network allowing you to send mail and reach port 587?

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
  #10 (permalink)  
Old April 18th, 2010, 12:08 AM
Registered User
 
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Of the four possible solutions, I am only unsure about the last one. How do I check whether the network is allowing me to send mail and reach port 587?

PS. Great book so far. Is there another book that dives deeper into 'Displaying and Updating Data'?
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
Unable to configure IIS website to use ASP.NET 2.0 japss ASP.NET 2.0 Professional 2 July 14th, 2008 09:14 AM
Unable to configure database mail pabnix SQL Server 2005 0 February 23rd, 2008 07:06 AM
Question Re Sending mail in Chapter 3 _fluffy_ BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 5 January 8th, 2007 11:30 PM
problems sending mail with java mail gandacuboy J2EE 2 December 20th, 2006 02:05 PM
Sending both text mail and HTML mail - CDONTS madhukp Classic ASP Basics 1 October 8th, 2003 01:05 AM



All times are GMT -4. The time now is 10:53 AM.


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