I am using C#.NET 4.0 and would like to send an email to an address with a subject and a body, the body will contain some information from a few text-boxes in my application
Is smtp.server.com really an SMTP server? You need to replace that with a real one. Your ISP probably provides you one, but it will likely only relay for emails originating from an address that your ISP owns.
I have worked with three well known ISP’s to host my client’s websites. All three ISP's instructed me to use “localhost” as the smtp server name.
Probably your authentication (credentials) or servername/port is not correct.
Try this:
MailMessage mailMsg = new MailMessage();
mailMsg.To.Add("test@hotmail.com");
// From
MailAddress mailAddress = new MailAddress("you@hotmail.com");
mailMsg.From = mailAddress;
// Subject and Body
mailMsg.Subject = "subject";
mailMsg.Body = "body";
// Init SmtpClient and send on port 587 in my case. (Usual=port25)
SmtpClient smtpClient = new SmtpClient("mailserver", 587);
System.Net.NetworkCredential credentials =
new System.Net.NetworkCredential("username", "password");
smtpClient.Credentials = credentials;
smtpClient.Send(mailMsg);
you cannot leave this string:
smtp.server.com
you should have there the name of your smtp server, usually something like mail.yourcompanyname.com or smtp.yourcompanyname.com
Add this:
SmtpServer.EnableSsl = true;