I Write code to send e-mail from an ASP.NET application..Is this correct for that or need some changes..any changes in the code will be happilly acceptable..

MailMessage mailMess = new MailMessage ();
mailMess.From = "abc@gmail.com";
mailMess.To = "xyz@gmail.com";
mailMess.Subject = "Test email";
mailMess.Body = "Hi This is a test mail.";
SmtpMail.SmtpServer = "localhost";
SmtpMail.Send (mailMess);

I am beginner in this field recently join Online Dot Net training course so I want to clear my doubt

Your code is close. Try these two minor fixes:


If you still have an issue, or if you just want to use some other email host server (i.e. post-office) add this code:

SmtpMail.Credentials = New System.Net.NetworkCredential("Your post Office Username", "and Password";
SmtpMail.Host = "your mail server (ie. smtp.mailhost.net)";

optionally if your server supports these:

SmtpMail.Timeout=15000; (15 seconds)

Also, optionally if you want to send HTML in the message:

mailMess.IsBodyHtml = True;

That covers how I user it over and over and over!