The following is my code for sending email from my contact us page of my website.
try
{
MailMessage Msg = new MailMessage();
// Sender e-mail address.
Msg.From = new MailAddress(txtEmail.Text);
// Recipient e-mail address.
Msg.Subject = txtSubject.Text;
Msg.Body = txtMessage.Text;
Msg.IsBodyHtml = true;
// your remote SMTP server IP.
SmtpClient smtp = new SmtpClient();
smtp.Host = "mail.dhuvara.com";
smtp.Port = 25;
Msg.Priority = MailPriority.Normal;
smtp.Credentials = new System.Net.NetworkCredential("
[email protected]", "SolaiMail");
smtp.EnableSsl = true;
smtp.Send(Msg);
//Msg = null;
lbltxt.Text = "Thanks for Contact us";
// Clear the textbox valuess
txtName.Text = "";
txtSubject.Text = "";
txtMessage.Text = "";
txtEmail.Text = "";
}
catch (Exception ex)
{
Console.WriteLine("{0} Exception caught.", ex);
}