Click here to Skip to main content
13,248,766 members (45,563 online)
Rate this:
Please Sign up or sign in to vote.
I tried to send Email from I am using this code

MailMessage msg = new MailMessage();
            msg.From = new MailAddress("");
            msg.Subject = TextBox2.Text;
            msg.Body = TextBox3.Text;
            SmtpClient sc = new SmtpClient("", 25);
            sc.Credentials = new NetworkCredential("username", "xxxxxx", "");
            LabelResult.Text = "Mail sent";
            LabelResult.Font.Size = 30;

and I get this error

System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: The remote name could not be resolved: '' 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.SmtpClient.Send(MailMessage message) --- End of inner exception stack trace --- at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.Button1_Click(Object sender, EventArgs e)

any help please!
Posted 26-Aug-12 23:42pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 7

protected void SendMail()
    // Gmail Address from where you send the mail
    var fromAddress = "";
    // any address where the email will be sending
    var toAddress = YourEmail.Text.ToString();
    //Password of your gmail address
    const string fromPassword = "Password";
     // Passing the values and make a email formate to display
    string subject = YourSubject.Text.ToString();
    string body = "From: " + YourName.Text + "\n";
    body += "Email: " + YourEmail.Text + "\n";
    body += "Subject: " + YourSubject.Text + "\n";
    body += "Question: \n" + Comments.Text + "\n";
    // smtp settings
    var smtp = new System.Net.Mail.SmtpClient();
        smtp.Host = "";
        smtp.Port = 587;
        smtp.EnableSsl = true;
        smtp.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;
        smtp.Credentials = new NetworkCredential(fromAddress, fromPassword);
        smtp.Timeout = 20000;
    // Passing values to smtp object
    smtp.Send(fromAddress, toAddress, subject, body);
protected void Button1_Click(object sender, EventArgs e)
        //here on button click what will done
        DisplayMessage.Text = "Your Comments after sending the mail";
        DisplayMessage.Visible = true;
        YourSubject.Text = "";
        YourEmail.Text = "";
        YourName.Text = "";
        Comments.Text = "";
    catch (Exception) { }

I have used above Code and it's working fine.
Member 10695198 22-May-14 5:33am
how we can attach a file using this code
Rate this: bad
Please Sign up or sign in to vote.

Solution 5

This error message is quite self-explanatory: The remote name could not be resolved: ''
You cannot create a connection to the SMTP server you have specified.

There is nothing wrong with your code. You just need to check why you can't access the SMTP ('') server

For starters, try pinging from the machine your application is running on.
Rate this: bad
Please Sign up or sign in to vote.

Solution 4

Try This, By use of below sample code you can send email with attachment.[^]
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

string RoMaMailID = System.Configuration.ConfigurationManager.AppSettings.Get("FromMailID");
string RoMaMailServer = System.Configuration.ConfigurationManager.AppSettings.Get("MailServerName");
string RoMaUserName = System.Configuration.ConfigurationManager.AppSettings.Get("USername");
      string RoMaPassword = System.Configuration.ConfigurationManager.AppSettings.Get("Password");

string Subject = "Test Mail";
          System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(RoMaMailServer);
          if (!RoMaUserName.ToString().Equals("")) {
              client.UseDefaultCredentials = false;
              client.Credentials = new System.Net.NetworkCredential(RoMaUserName, RoMaPassword);
          client.Port = 465;

          client.EnableSsl = true;
          client.DeliveryMethod = System.Net.Mail.SmtpDeliveryMethod.Network;

System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage("Roadside Systems<" + FromMailID+ ">",To, Subject, Message);
           Mail.IsBodyHtml = true;
               SendEmail(To, Subject, Message);
               Response.Write("Mail send Successfully");
           catch (Exception Ex)
TorstenH. 27-Aug-12 7:05am
?? and your solution is to copy some code from somewhere else or what?
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

Please use a local Email-Server for testing:[^]

It's free.

your provider will limit the number of accesses to the pop/smtp and might also ban you completely if you try to shoot the SMTP/POP with strange commands.

Your Exception
The remote name could not be resolved: '' 

says that the address is not existing or at least can not be resolved to an IP address.
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

If you cannot connect to any smtp you should consult your network department because it seems to be a general problem with a firewall between you and your provider. You can also try to disable your local windows firewall.

Also you can refer the same question in System.Net.Mail.SmtpException:Failure sending mail[^]

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.171114.1 | Last Updated 22 Apr 2014
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100