I wish to incorporate e-mail in my page such that when a user had pressed a button, an email will be sent to the recipient. This has been my code.
MailMessage mail = new MailMessage(); mail.To = "email@example.com"; mail.From = "firstname.lastname@example.org"; mail.Subject = "this is a test email."; mail.BodyFormat = MailFormat.Html; mail.Body = "this is my test email body.<br><b>this part is in bold</b>"; SmtpMail.SmtpServer = "localhost"; //your real server goes here SmtpMail.Send( mail );
When I had uploaded the page in my site I received this error:The transport failed to connect to the server.
and the error is pointed to the statement SmtpMail.SmtpServer = "localhost";
What is the problem in my code?