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 February 24th, 2012, 02:20 PM
Authorized User
 
Join Date: Feb 2012
Posts: 22
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("[email protected]", "username        
        myMessage.To.Add(new MailAddress("[email protected]", "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;[email protected]&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 "[email protected]" 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("[email protected]", "username

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

Last edited by happyandstable; February 24th, 2012 at 05:39 PM..
 
Old February 24th, 2012, 06:41 PM
Authorized User
 
Join Date: Feb 2012
Posts: 22
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;[email protected]&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 06:45 PM..
The Following User Says Thank You to happyandstable For This Useful Post:
Imar (February 25th, 2012)





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





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