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

July 14th, 2011, 12:08 PM
|
|
Authorized User
|
|
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Chapter 9 try it out (page 319-320)
Hi Imar,
I keep getting the following error when doing the example on pages 319 and 320
Server Error in '/Site' Application.
No connection could be made because the target machine actively refused it 208.73.210.29:25
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: No connection could be made because the target machine actively refused it 208.73.210.29:25
Source Error:
Line 18:
Line 19: SmtpClient mySmtpClient = new SmtpClient();
Line 20: mySmtpClient.Send(myMessage);
Line 21:
Line 22: }
Source File: e:\BegASPNET\Site\Demos\Email.aspx.cs Line: 20
Stack Trace:
[SocketException (0x274d): No connection could be made because the target machine actively refused it 208.73.210.29:25]
System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +225
System.Net.ServicePoint.ConnectSocketInternal(Bool ean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception) +279
[WebException: Unable to connect to the remote server]
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +6054548
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +314
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +322
System.Net.Mail.SmtpConnection.GetConnection(Servi cePoint servicePoint) +146
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.]
The code is exactly like in the book. Can you take a look and help me out.
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
Thanks.
|
|

July 14th, 2011, 12:11 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Hi there,
Have you tried specifying a username / password, ssl and/or port number in the web.config? Who's the administrator of the SMTP server on this IP address? Maybe they can provide you with the correct setup details?
Imar
|
|

July 14th, 2011, 12:43 PM
|
|
Authorized User
|
|
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
I added this to the web.config file
Code:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network"
from ="xxx xxx < [email protected]>">
<network enableSsl="false" userName="[email protected]" port="25" password="xxxx" host="smtp.sercureserver.net"/>
</smtp>
</mailSettings>
I use GoDaddy for my hosting and email.
|
|

July 14th, 2011, 12:59 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Maybe GoDaddy doesn't allow you to connect to a different server, or the server doesn't use port 25? Doesn't GoDaddy provide you with a SMTP server?
Imar
|
|

July 15th, 2011, 11:19 AM
|
|
Authorized User
|
|
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
I switched the settings to use gmail and i still get the error message.
Code:
<system.net>
<mailSettings>
<smtp deliveryMethod="Network"
from ="name <[email protected]>">
<network enableSsl="true" host ="smtp.gmail.com" port="467" password="password" userName ="[email protected]" />
</smtp>
</mailSettings>
</system.net>
The error keeps pointing to this
Code:
MailMessage myMessage = new MailMessage();
myMessage.Subject = "Test Message";
myMessage.Body = "Hello world, from Planet Wrox";
myMessage.From = new MailAddress("[email protected]", "name");
myMessage.To.Add(new MailAddress([email protected]", "Receiver Name"));
SmtpClient mySmtpClient = new SmtpClient();
mySmtpClient.Send(myMessage);
Thanks
|
|

July 15th, 2011, 12:00 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
I think Gmail uses port 587. Take a look here: http://imar.spaanjaars.com/505/using...at-require-ssl for sample code that works with Gmail.
Hope this helps,
Imar
|
|

October 26th, 2011, 03:00 PM
|
|
Authorized User
|
|
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Hi Imar,
I used the sample you provided for gmail setup in web.config. I keep getting this message.
Please note that when i have it send to a temp folder on my desktop it works fine. Can you please take a look. Thanks.
No connection could be made because the target machine actively refused it 72.167.238.201:587
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: No connection could be made because the target machine actively refused it 72.167.238.201:587
Source Error:
Line 102: MailMessage message = new MailMessage(fromAddress, toAddress, mailSubject, mailBody);
Line 103: message.IsBodyHtml = false;
Line 104: smtpClient.Send(message);
Line 105: }
Line 106:
Stack Trace
No connection could be made because the target machine actively refused it 72.167.238.201:587
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: No connection could be made because the target machine actively refused it 72.167.238.201:587
Source Error:
Line 102: MailMessage message = new MailMessage(fromAddress, toAddress, mailSubject, mailBody);
Line 103: message.IsBodyHtml = false;
Line 104: smtpClient.Send(message);
Line 105: }
Line 106:
|
|

October 29th, 2011, 09:41 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Can you show your web.config file? It works for me with the code from my article so if you use the same settings, your network may be blocking the connection.
Cheers,
Imar
|
|

October 29th, 2011, 11:12 AM
|
|
Authorized User
|
|
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
|
|
Here is the web.config code:
Thanks
Code:
<configuration>
<appSettings>
<add key="MyEmailAddr" value="[email protected]"/>
<add key="ToEmailAddr" value="[email protected]"/>
<add key="EmailHost" value="smtp.gmail.com"/>
<add key="FromEmailAddr" value="[email protected]"/>
</appSettings>
<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network enableSsl="true"
port="587"
userName="[email protected]"
password="xxx"
host="smtp.gmail.com"/>
</smtp>
</mailSettings>
<!-- <mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="c:\Documents and Settings\xxx\Desktop\mail"/>
</smtp>
</mailSettings> -->
</system.net>
|
|

October 29th, 2011, 11:34 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
Then I think it's an issue in your local network such as a firewall blocking access to port 587.
I copied and pasted your config code and then send a message using it. Works fine for me.
Cheers,
Imar
|
|
 |
|