Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET .NET HTML SMTP
I tried to send Email from asp.net I am using this code
 

MailMessage msg = new MailMessage();
            msg.From = new MailAddress("username@domain.com");
            msg.To.Add(TextBox1.Text);
            msg.Subject = TextBox2.Text;
            msg.Body = TextBox3.Text;
 
            SmtpClient sc = new SmtpClient("wmail.link.net", 25);
            sc.Credentials = new NetworkCredential("username", "xxxxxx", "wmail.link.net");
            sc.Send(msg);
            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: 'wmail.link.net' 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 22:42pm
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 7

protected void SendMail()
{
    // Gmail Address from where you send the mail
    var fromAddress = "Gmail@gmail.com";
    // 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.gmail.com";
        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)
{
    try
    {
        //here on button click what will done
        SendMail();
        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.
  Permalink  
Comments
Member 10695198 at 22-May-14 5:33am
   
how we can attach a file using this code
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 5

This error message is quite self-explanatory: The remote name could not be resolved: 'wmail.link.net'
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 ('wmail.link.net') server

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

Solution 4

Try This, By use of below sample code you can send email with attachment.
 

http://hemantrautela.blogspot.in/2012/09/advance-email-sending-codecnet-with.html[^]
  Permalink  
Rate this: bad
good
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;
           try
           {
               //client.Send(Mail);
               SendEmail(To, Subject, Message);
               Response.Write("Mail send Successfully");
           }
           catch (Exception Ex)
           {
               Response.Write(Ex.Message);
           }
  Permalink  
Comments
TorstenH. at 27-Aug-12 7:05am
   
?? and your solution is to copy some code from somewhere else or what?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Please use a local Email-Server for testing: http://www.hmailserver.com/[^]
 
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: 'wmail.link.net' 
 
says that the address is not existing or at least can not be resolved to an IP address.
  Permalink  
Rate this: bad
good
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[^]
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 365
1 Nirav Prabtani 252
2 Richard Deeming 215
3 CHill60 170
4 _Amy 145
0 OriginalGriff 8,104
1 Sergey Alexandrovich Kryukov 7,045
2 Maciej Los 4,039
3 Peter Leow 3,738
4 CHill60 2,912


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 22 Apr 2014
Copyright © CodeProject, 1999-2014
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