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 February 24th, 2012, 01:20 PM
Authorized User
Points: 97, Level: 1
Points: 97, Level: 1 Points: 97, Level: 1 Points: 97, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 12
Thanks: 0
Thanked 4 Times in 4 Posts
Default Help with email from chapter 09

Here is what is in my page lode

Code:
  protected void Page_Load(object sender, EventArgs e)
    {
        MailMessage myMessage = new MailMessage();
        myMessage.Subject = "Test Message";
        myMessage.Body = "Hello world from Planet Wrox";
        myMessage.From = new MailAddress("username@provider.com", "username        
        myMessage.To.Add(new MailAddress("username@provider.com", "usename"));

        SmtpClient myStmpClient = new SmtpClient();
        myStmpClient.Send(myMessage);
    }
and in my web confige file there is this

Code:
  <system.net>
      <mailSettings>
          <smtp deliveryMethod="Network" from="username &lt;username@yahoo.com&gt;">
              <network host="smtp.mail.yahoo.com" userName="username" password="mypassword" port="465" enableSsl="true"/>
          </smtp>
      </mailSettings>      
  </system.net>
When I run the page in the browers this is what I get

Server Error in '/BeginningASPdotNET4' 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 18:
Line 19: SmtpClient myStmpClient = new SmtpClient();
Line 20: myStmpClient.Send(myMessage);
Line 21: }
Line 22: }


Source File: e:\Websites\BeginningASPdotNET4\Chapter09\E-mailDemo.aspx.cs Line: 20

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) +6210536
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) +222
System.Net.Mail.SmtpClient.GetConnection() +50
System.Net.Mail.SmtpClient.Send(MailMessage message) +1496

[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1829
Chapter09_E_mailDemo.Page_Load(Object sender, EventArgs e) in e:\Websites\BeginningASPdotNET4\Chapter09\E-mailDemo.aspx.cs:20
System.Web.Util.CalliHelper.EventArgFunctionCaller (IntPtr fp, Object o, Object t, EventArgs e) +14
System.Web.Util.CalliEventHandlerDelegateProxy.Cal lback(Object sender, EventArgs e) +35
System.Web.UI.Control.OnLoad(EventArgs e) +91
System.Web.UI.Control.LoadRecursive() +74
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2207

Would appreciate any help you can give me Love This Book!

Also "username@provider.com" in the real code is acctually my real username @yahoo.com just as my password is my real password just did not want to post it here and replaced it with generics

Just noticed that in my code quote there is this

myMessage.From = new MailAddress("username@provider.com", "username

there is a missing ); at the end but in the actual page it is there.

Last edited by happyandstable; February 24th, 2012 at 04:39 PM.
Reply With Quote
  #2 (permalink)  
Old February 24th, 2012, 05:41 PM
Authorized User
Points: 97, Level: 1
Points: 97, Level: 1 Points: 97, Level: 1 Points: 97, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 12
Thanks: 0
Thanked 4 Times in 4 Posts
Default

In case anyone else runs into this problem here is the fix and I will explain the difference.

Code:
  <system.net>
      <mailSettings>
          <smtp deliveryMethod="Network" from="username &lt;username@yahoo.com&gt;">
              <network host="smtp.mail.yahoo.com" userName="username" password="mypassword" port="587" enableSsl="false"/>
          </smtp>
      </mailSettings>      
  </system.net>
The port number is changed from the original I used "465", you need to use port "587 to connect to yahoo's stmp server.

yahoo mail does not support secure sockets so you have to set enableSsl to "false"


works fine for me now just thought others would like to know

Last edited by happyandstable; February 24th, 2012 at 05:45 PM.
Reply With Quote
The Following User Says Thank You to happyandstable For This Useful Post:
Imar (February 25th, 2012)
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
Chapter 2 -WPFSPListApp 11/09/2011 peterkao87 BOOK: Beginning SharePoint 2010 Development 0 November 9th, 2011 02:24 PM
CH 09 AjaxMail SQL coders4hire BOOK: Professional Ajax ISBN: 978-0-471-77778-6 2 June 22nd, 2006 08:03 PM
Beginning Visual C# Exercises - Chapter 09 seblake C# 0 July 27th, 2004 03:23 PM



All times are GMT -4. The time now is 01:12 PM.


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