Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I tried to send email in my site but I got this Error:
please help... :(

The remote name could not be resolved: ''

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.WebException: The remote name could not be resolved: ''

Source Error:

Line 31:
Line 32: SmtpClient mySmtpClient = new SmtpClient();
Line 33: mySmtpClient.Send(myMessage);
Line 34: }
Line 35: }

Source File: c:\inetpub\whosts\\httpdocs\Index.aspx.cs Line: 33

Stack Trace:

[WebException: The remote name could not be resolved: '']
System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout) +5483851
System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback) +202
System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback) +21
System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout) +332
System.Net.Mail.SmtpConnection.GetConnection(String host, Int32 port) +160
System.Net.Mail.SmtpTransport.GetConnection(String host, Int32 port) +159
System.Net.Mail.SmtpClient.GetConnection() +35
System.Net.Mail.SmtpClient.Send(MailMessage message) +1213
[SmtpException: Failure sending mail.]
System.Net.Mail.SmtpClient.Send(MailMessage message) +1531
_Default.Button1_Click(Object sender, EventArgs e) in c:\inetpub\whosts\\httpdocs\Index.aspx.cs:33
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +111
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +110
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


I thnk u can do the following way..
Just handle the remote error exception.

    // try to download file here
catch (WebException ex)
    if (ex.Status == WebExceptionStatus.ProtocolError)
        if (((HttpWebResponse)ex.Response).StatusCode == HttpStatusCode.NotFound)
            int code = (Int32)response.StatusCode;
                 // handle the 404 here
Share this answer
In my opinion, this error message is quite self-explanatory: You cannot create a connection to the SMTP server you have specified.

There is probably nothing wrong with your code as it is.

You need to check why you can't access the SMTP server.

For starters, try pinging from the machine your application is running on.
Share this answer
If it is having issues resolving the server name, then that is likely a DNS issue on the server. CS simply goes to the connect to the given hostname, and the system will automatically try to resolve the hostname into an IP using the DNS servers the server is configured to use.

Take not of the email server setting in CS, then log into the server, open a command prompt, and type "nslookup". if it can't resolve it, then you might want to check the DNS settings for the domain, or the DNS servers your server is set up to use.

BTW: Before that, just check it's not the firewall creating the issue. Port being used is open and permissions given.
Share this answer
Nima.naqipoor 14-Jul-10 0:09am    
Reason for my vote of 4
good boy

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900