Cannot use smtpclient to send mail with localhost iis

I have an asp.net mvc application running on a local iis website that does not send mail using SmtpClient from System.Net.Mail. I am trying to send mail to my hotmail address and I get a socket exception. Any idea what could be the problem?

using(var message = new MailMessage()) { message.From = new MailAddress(AdminEmail); message.To.Add(new MailAddress(to)); message.Subject = subject; message.Body = body; message.IsBodyHtml = false; var mailClient = new SmtpClient(); mailClient.Send(message); } 

Here is the exception:

 {System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:25 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)} 

I think the default application pool does not have access to intepub \ wwwroot. Here is the error I get when trying to test the connection:

The server is configured to use pass-through authentication with a built-in account to access the specified physical path. However, IIS Manager cannot verify that it has access to the built-in account. Verify that the application pool identifier has read access to the physical path. If this server is joined to a domain and the application pool identifier is NetworkService or LocalSystem, make sure that \ $ has read access to the physical path. Then check these settings again.

+4
source share
4 answers

Based on your responses to my comments above Joe, you do not have SMTP enabled on your local computer. Vista does not ship with SMTP.

Thus, you will either have to install a third-party SMTP application that will run in Vista, or use another application to send, in which case your Hotmail account can allow you to send outgoing messages through it. I do not use Hotmail, so I don’t know if it will be or not, but it should be something like smtp.hotmail.com and your credentials. My main account is a gmail account, so I can use it through smtp.gmail.com and of course my credentials.

+3
source

For development on your local computer, you can also use the delete folder:

http://www.codersbarn.com/post/2008/11/30/ASPNET-Contact-Form.aspx

+2
source

Instead of trying to configure SMTP locally, why don't you just set up an SMTP connection for direct sending via hotmail, just add configuration items to web.config to enable everything.

Edit

I think this article I wrote some time ago can help you.

0
source

Try explicitly setting the SmtpClient host.

Example:
SmtpClient mailClient = new SmtpClient ();

mailClient.Host = "127.0.0.1";

mailClient.Send (message);

-1
source

All Articles