There is nothing wrong with the code, but you havent setup your smtp server. you are using <network host="localhost"/> where smtp is not setup. so either use your company email server i.e. mail.yourcompanydomain.com if you dont have smtp server setup at your company, then you can use Gmail, just create an account on gmail and you can use smtp.gmail.com as your stmp server with the user name and password that you have created. use the following example...
public static void CreateTestMessage1(string server, int port)
{
string to = "someone@somewhere.com";
string from = "me@somewhere.com";
string subject = "Using the new SMTP client.";
string body = @"Using this new feature, you can send an e-mail message from an application very easily.";
MailMessage message = new MailMessage(from, to, subject, body);
SmtpClient client = new SmtpClient("smtp server name");
client.Credentials = new System.Net.NetworkCredential("username", "password");
try {
client.Send(message);
}
catch (Exception ex) {
Console.WriteLine("Exception caught in CreateTestMessage1(): {0}",
ex.ToString() );
}
}
also as Mark said, please use the code block feature when you post a code in your question. :)