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 <[email protected]>">
<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.