Wrox Programmer Forums
|
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 September 16th, 2010, 12:49 PM
Authorized User
 
Join Date: Aug 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 9 sending email pg 323-326

I keep getting this error when the send message is called. Any suggestion!

Server Error in '/Site' 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 55:
Line 56: SmtpClient mySmtpClient = new SmtpClient();
Line 57: mySmtpClient.Send(myMessage);
Line 58:
Line 59: Message.Visible = true;


Source File: c:\Maintenance Request System\Site\Controls\ContactForm.ascx.cs Line: 57

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
Controls_ContactForm.SendButton_Click(Object sender, EventArgs e) in c:\Maintenance Request System\Site\Controls\ContactForm.ascx.cs:57
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563


web.config

Code:
configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0"/>
    
  </system.web>
   <system.net>
    <mailSettings>
      <smtp deliveryMethod="Network" from="my name&lt;[email protected]&gt;">
        <network host="1123smtp.123.com" />
       
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
contactform.ascx

Code:
protected void SendButton_Click(object sender, EventArgs e)
    {
        if (Page.IsValid)
    {
      string fileName = Server.MapPath("~/App_Data/ContactForm.txt");
      string mailBody = File.ReadAllText(fileName);

      mailBody = mailBody.Replace("##UserID##", UserID.Text);
      mailBody = mailBody.Replace("##FirstName##", FirstName.Text);
      mailBody = mailBody.Replace("##LastName##", LastName.Text);
      mailBody = mailBody.Replace("##RoomNum##", RoomNum.Text);
      mailBody = mailBody.Replace("##HomePhone##", PhoneNum.Text);
      mailBody = mailBody.Replace("##Location##", Location.Text);
      mailBody = mailBody.Replace("##Notify##", Notify.Text);
      mailBody = mailBody.Replace("##Comments##", Comments.Text);

      MailMessage myMessage = new MailMessage();
      myMessage.Subject = "Response from web site";
      myMessage.Body = mailBody;

      myMessage.From = new MailAddress("[email protected]", "Sender Name");
      myMessage.To.Add(new MailAddress("[email protected]", "Receiver Name"));

      SmtpClient mySmtpClient = new SmtpClient();
      mySmtpClient.Send(myMessage);

      Message.Visible = true;
      FormTable.Visible = false;
    }
  }
}
 
Old September 16th, 2010, 01:44 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,

Which SMTP host are you using? The one you've configured seems to be a fake one? Maybe your host requires you to use SSL?

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 September 17th, 2010, 01:43 PM
Authorized User
 
Join Date: Aug 2010
Posts: 13
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sending Message

I am a federal employee, using SMTP is not allowed. We are also required to use stored procedures. How can I send mail from the contact form?
 
Old September 17th, 2010, 03:17 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

If you just want to continue with the exercises, take a look at the last section on page 318 that shows how to configure a local drop folder.

Otherwise, you need to talk to you network operator for a work around. If SMTP is not allowed, you can't send e-mail using the SmtpClient.

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!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 9:page 310,sending email messages Arya BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 4 January 4th, 2010 09:51 PM
Sending email Sheraz Khan Classic ASP Basics 1 December 12th, 2009 12:58 AM
Sending Email soccers_guy10 Pro VB 6 3 February 11th, 2004 10:41 AM





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