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
| 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 Search this Thread Display Modes
  #1 (permalink)  
Old July 14th, 2011, 12:08 PM
Authorized User
Points: 221, Level: 4
Points: 221, Level: 4 Points: 221, Level: 4 Points: 221, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default 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.
Reply With Quote
  #2 (permalink)  
Old July 14th, 2011, 12:11 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
  #3 (permalink)  
Old July 14th, 2011, 12:43 PM
Authorized User
Points: 221, Level: 4
Points: 221, Level: 4 Points: 221, Level: 4 Points: 221, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

I added this to the web.config file

Code:
 
<system.net>
        <mailSettings>
            <smtp deliveryMethod="Network"
                  from ="xxx xxx &lt; xxx@pctoolmanconsulting.com&gt;">
                <network enableSsl="false" userName="xxx@pctoolmanconsulting.com" port="25" password="xxxx" host="smtp.sercureserver.net"/>

            </smtp>
        </mailSettings>
I use GoDaddy for my hosting and email.
Reply With Quote
  #4 (permalink)  
Old July 14th, 2011, 12:59 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
  #5 (permalink)  
Old July 15th, 2011, 11:19 AM
Authorized User
Points: 221, Level: 4
Points: 221, Level: 4 Points: 221, Level: 4 Points: 221, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

I switched the settings to use gmail and i still get the error message.

Code:
 <system.net>
        <mailSettings>
            <smtp deliveryMethod="Network"
                  from ="name &lt;xxx@gmail.com&gt;">
                <network enableSsl="true" host ="smtp.gmail.com" port="467" password="password" userName ="xxx@gmail.com"   />

            </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("xxx@gmail.com", "name");
        myMessage.To.Add(new MailAddress(xxx@gmail.com", "Receiver Name"));

        SmtpClient mySmtpClient = new SmtpClient();
        mySmtpClient.Send(myMessage);
Thanks
Reply With Quote
  #6 (permalink)  
Old July 15th, 2011, 12:00 PM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
  #7 (permalink)  
Old October 26th, 2011, 03:00 PM
Authorized User
Points: 221, Level: 4
Points: 221, Level: 4 Points: 221, Level: 4 Points: 221, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

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:
Reply With Quote
  #8 (permalink)  
Old October 29th, 2011, 09:41 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
  #9 (permalink)  
Old October 29th, 2011, 11:12 AM
Authorized User
Points: 221, Level: 4
Points: 221, Level: 4 Points: 221, Level: 4 Points: 221, Level: 4
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2010
Posts: 50
Thanks: 7
Thanked 0 Times in 0 Posts
Default

Here is the web.config code:

Thanks

Code:
<configuration>
  <appSettings>
    <add key="MyEmailAddr" value="xxx@gmail.com"/>
    <add key="ToEmailAddr" value="xxx@gmail.com"/>
    <add key="EmailHost" value="smtp.gmail.com"/>
    <add key="FromEmailAddr" value="xxx@gmail.com"/>
  </appSettings>
  <system.net>
       <mailSettings>
           <smtp deliveryMethod="Network" from="xxx@gmail.com">
               <network enableSsl="true"
                 port="587"
                 userName="xxx@gmail.com"
                 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>
Reply With Quote
  #10 (permalink)  
Old October 29th, 2011, 11:34 AM
Imar's Avatar
Wrox Author
Points: 72,055, Level: 100
Points: 72,055, Level: 100 Points: 72,055, Level: 100 Points: 72,055, Level: 100
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
Default

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
__________________
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!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Try it out on page 319 fredfenk BOOK: Beginning ASP.NET 4 : in C# and VB 1 March 31st, 2011 12:13 PM
Chapter 2 page 23 youngbones BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 March 30th, 2011 12:21 PM
Chapter 9 - Try It OUT on page 319 Windblown BOOK: Beginning ASP.NET 4 : in C# and VB 6 January 29th, 2011 10:23 AM
chapter 2 - page 41 problem creating the page.. jorjiana BOOK: Beginning Oracle Application Express ISBN: 9780470388372 2 August 22nd, 2009 04:25 AM
Page 319: Exercise 1 kiwibrit BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 2 July 3rd, 2009 10:46 AM



All times are GMT -4. The time now is 03:50 PM.


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