I need to be able to send an e-mail to the specified e-mail address from the application. The following is the code snippet I am using to execute the task: --------------------------------------------------------------------------------------- MailMessage Message = new MailMessage(); Message.IsBodyHtml = true; Message.To.Add( new MailAddress(mToEmail)) ; Message.From = new MailAddress(mFromEmail); Message.Subject = mSubject; Message.Body = mBody ; SmtpClient smtp = new SmtpClient(mSmtpHost, mSmtpPort); smtp.Send(Message); --------------------------------------------------------------------------------------- I am using the following information to send an e-mail: smtpHost ='mail.calinurseexpress.com' smtpPort ='587' ---------------------------------------------------------------------------------------- The application is sending an e-mail in the synchronous mode. I am getting the following error: System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable host 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) --- End of inner exception stack trace --- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) at System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) at System.Net.Mail.SmtpClient.GetConnection() at System.Net.Mail.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) I also tried to use localhost: SmtpClient smtp = new SmtpClient('localhost', mSmtpPort); It did not work and I got the same error. Do I need to provide the port infomation? If yes, is the port info correct? I am use 587 port. What I am missing? Post Edited (Lana) : 3/21/2006 3:40:46 AM GMT
Lana, is there a user name and password that might need to be supplied here? You can supply the SMTP information in the web.config file as follows, if you didn't know; <system.net> <mailSettings> <smtp from="[email protected]"> <network port="25" host="mail.mysite.com" userName="[email protected]" password="password"/> </mailSettings> </system.net> Default mail port is 25, which is not necessary to supply if it is 25. Here is a B-Basic article on sending mail in ASP.NET 2.0; http://www.codeproject.com/useritems/EmailApplication.asp Hope this helps! BZ
This works for me... Not sure if it is the proper way to do it or not... <mailSettings> <smtp from="[email protected]"> <network host="localhost" port="25" defaultCredentials="true" /> </smtp> </mailSettings>
hi I have a same error in my remoting application. every thing is ok if i am calling my remote method from a windows application. but getting the error System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable host,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),- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream(),at System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessAndSend(IMessage msg, ITransportHeaders headers, Stream inputStream),at System.Runtime.Remoting.Channels.Http.HttpClientTransportSink.ProcessMessage(IMessage msg, ITransportHeaders requestHeaders, Stream requestStream, ITransportHeaders& responseHeaders, Stream& responseStream),at System.Runtime.Remoting.Channels.SoapClientFormatterSink.SyncProcessMessage(IMessage msg),Exception rethrown at [0]:,at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg),at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type) when iam calling the method from a windows service with exact same code. so please any one have any isea to solve this let me know.its very urgent nibedita