Wrox Programmer Forums
| 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 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
  #1 (permalink)  
Old January 20th, 2011, 08:11 PM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 - Try It OUT on page 319

Imar- Up to this point, I have been able to solve my own problems while working through your very good book. However, in Chapter 9 the Try It OUT on page 319 has me stumped. Below is my Web.Config, Code behind, and the reported error. my Email host, Username, and password(Blocked here for security) and port number are correctly entered

Any light you might be able to shed on this problem will be greatly appreciated!


Web.Config partial:

Code:
<system.net>
     <mailSettings>
         <smtp deliveryMethod="Network" from="Dan &lt;w0kks@sbcglobal.net&gt;">
           <network enableSsl="true" userName="w0kks@sbcglobal.net" 
                         password="****" host="smtp.att.yahoo.com" port="465" />
          </smtp>
      </mailSettings>
</system.net>

Code Behind for Demos/Email.aspx:

Code:
Imports System.Net.Mail
Partial Class Demos_Email
    Inherits BasePage

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim myMessage As MailMessage = New MailMessage
        myMessage.Subject = "Test Message"
        myMessage.Body = "Hello World, from Planet Wrox"
        myMessage.From = New MailAddress("w0kks@sbcglobal.net", "Dan")
        myMessage.To.Add(New MailAddress("w0kks@sbcglobal.net", "Dan"))
        
        Dim mySmtpClient As SmtpClient = New SmtpClient
        mySmtpClient.Send(myMessage)

    End Sub
End Class


Reported error by WebBrowser
Server Error in '/' Application.
--------------------------------------------------------------------------------

An existing connection was forcibly closed by the remote host
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

Source Error:


Line 11:
Line 12: Dim mySmtpClient As SmtpClient = New SmtpClient
Line 13: mySmtpClient.Send(myMessage)
Line 14:
Line 15: End Sub


Source File: C:\BegASPNET\Site\Demos\Email.aspx.vb Line: 13

Stack Trace:


[SocketException (0x2746): An existing connection was forcibly closed by the remote host]
System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) +6132200
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +134

[IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.]
System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) +300
System.Net.DelegatedStream.Read(Byte[] buffer, Int32 offset, Int32 count) +45
System.Net.BufferedReadStream.Read(Byte[] buffer, Int32 offset, Int32 count) +105
System.Net.Mail.SmtpReplyReaderFactory.ReadLines(S mtpReplyReader caller, Boolean oneLine) +248
System.Net.Mail.SmtpReplyReaderFactory.ReadLine(Sm tpReplyReader caller) +16
System.Net.Mail.SmtpConnection.GetConnection(Servi cePoint servicePoint) +665
System.Net.Mail.SmtpTransport.GetConnection(Servic ePoint servicePoint) +170
System.Net.Mail.SmtpClient.GetConnection() +50
System.Net.Mail.SmtpClient.Send(MailMessage message) +1484

[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1811
Demos_Email.Page_Load(Object sender, EventArgs e) in C:\BegASPNET\Site\Demos\Email.aspx.vb:13
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207
  #2 (permalink)  
Old January 21st, 2011, 03:43 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

Your code and setup looks fine, so it must be a combination of the user name, mail server and port number.

Are you sure that the Yahoo server lets you send e-mail with that user name? And is the port number correct? Have you tried sending e-mail from, say, Outlook using these details?

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!
  #3 (permalink)  
Old January 26th, 2011, 05:06 PM
Registered User
 
Join Date: Jan 2011
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Imar-
Thanks for your prompt reply and confirming my code!

I appologize for the delay in replying. I do use MS Outlook 2007 for my E-mail program of choice, and it is configured as indicated in my web.config and works extremely well.

Deciding to attempt the KISS method, I removed the EnableSSL statement and changed the port # back to 25. This configuration will now send the e-mail as it is supposed to.

Thanks again for your assistance and a very good book!
  #4 (permalink)  
Old January 29th, 2011, 09:49 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
Default Same Problem

Hi,

I am having the same problem. Here is my code..

Protected Sub sendButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles sendButton.Click
If Page.IsValid Then
Dim fileName As String = Server.MapPath("~/App_Data/ContactForm.txt")
Dim mailBody As String = File.ReadAllText(fileName)

mailBody = mailBody.Replace("##Name##", Name.Text)
mailBody = mailBody.Replace("##Email##", EmailAddress.Text)
mailBody = mailBody.Replace("##PhoneHome##", PhoneHome.Text)
mailBody = mailBody.Replace("##PhoneWork##", PhoneWork.Text)
mailBody = mailBody.Replace("##Comments##", Comments.Text)

Dim myMessage As MailMessage = New MailMessage()
myMessage.Subject = "Response from web site"
myMessage.Body = mailBody

myMessage.From = New MailAddress("leewozywarren@gmail.com", "Sender Name")
myMessage.To.Add(New MailAddress("leewozywarren@gmail.com", "Receiver Name"))

Dim mySmtpClient As SmtpClient = New SmtpClient()
mySmtpClient.Send(myMessage)

Message.Visible = True
formTable.Visible = False
End If
End Sub
End Class

AND

<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="Lee Warren &lt;leewozywarren@gmail.com&gt;">
<network enableSsl="true" userName="leewozywarren@gmail.com" password="********" host="smtp.gamil.com"/>
</smtp>
</mailSettings>
</system.net>
  #5 (permalink)  
Old January 29th, 2011, 10:16 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Quote:
smtp.gamil.com
Shouldn't that be smtp.gmail.com ?

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!
  #6 (permalink)  
Old January 29th, 2011, 10:17 AM
Imar's Avatar
Wrox Author
Points: 70,322, Level: 100
Points: 70,322, Level: 100 Points: 70,322, Level: 100 Points: 70,322, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Also you may need to specify a port number as explained here: http://imar.spaanjaars.com/505/using...at-require-ssl

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!
  #7 (permalink)  
Old January 29th, 2011, 10:23 AM
Authorized User
Points: 285, Level: 5
Points: 285, Level: 5 Points: 285, Level: 5 Points: 285, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2010
Posts: 71
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Ahhh. screen blindness... that can catch you out. Let me look at the thread you mentioned and come back to you. Cheers.

Lee


Similar Threads
Thread Thread Starter Forum Replies Last Post
chapter 8, page 300 misken BOOK: Beginning SharePoint 2010 Development 3 September 13th, 2010 05:17 PM
chapter 2 - page 41 problem creating the page.. jorjiana BOOK: Beginning Oracle Application Express ISBN: 9780470388372 2 August 22nd, 2009 04:25 AM
Page 319: Exercise 1 kiwibrit BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 July 3rd, 2009 10:46 AM
Chapter 1, Page 23 golden_drifter BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 7 July 9th, 2004 12:12 AM
Chapter 1 page 74 dryan BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 2 June 16th, 2004 02:16 PM





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