Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 4 > BOOK: Beginning ASP.NET 4 : in C# and VB
|
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 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 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.
 
Old April 15th, 2010, 06:16 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
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.
 
Old April 16th, 2010, 02:31 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
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?
 
Old April 16th, 2010, 11:43 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
Old April 17th, 2010, 08:08 AM
Friend of Wrox
 
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
 
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.
 
Old April 17th, 2010, 09:50 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 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!
 
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'?





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 08: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 9th, 2007 12:30 AM
problems sending mail with java mail gandacuboy J2EE 2 December 20th, 2006 03:05 PM
Sending both text mail and HTML mail - CDONTS madhukp Classic ASP Basics 1 October 8th, 2003 01:05 AM





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