 |
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
|
|
|
|

April 15th, 2010, 06:03 PM
|
Registered User
|
|
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

April 15th, 2010, 06:16 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

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

April 16th, 2010, 02:31 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

April 16th, 2010, 11:37 AM
|
Registered User
|
|
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|

April 16th, 2010, 11:43 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

April 17th, 2010, 08:08 AM
|
Friend of Wrox
|
|
Join Date: Sep 2009
Posts: 165
Thanks: 5
Thanked 6 Times in 6 Posts
|
|
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
|

April 17th, 2010, 09:19 AM
|
Registered User
|
|
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|

April 17th, 2010, 09:50 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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
|

April 18th, 2010, 12:08 AM
|
Registered User
|
|
Join Date: Apr 2010
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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'?
|
|
 |
|