using System; using System.Net; using System.Net.Mail; using System.Configuration; using System.Web.UI; namespace www { public partial class Contact : Page { protected void Page_Load(object sender, EventArgs e) { } protected void btnPost_Click(object sender, EventArgs e) { string name = txName.Text.Trim(); string email = txEmail.Text.Trim(); string subject = txSubject.Text.Trim(); string reason = dropReason.SelectedItem.Text; string message = txMessage.Text.Trim(); if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(email) || string.IsNullOrEmpty(message)) return; try { var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential( ConfigurationManager.AppSettings["SmtpUser"], ConfigurationManager.AppSettings["SmtpPass"] ) }; string body = string.Format( "Name: {0}\nEmail: {1}\nReason: {2}\n\n{3}", name, email, reason, message ); var mail = new MailMessage { From = new MailAddress("atsigma@gmail.com", "AdvTech Website"), Subject = "[AdvTech Contact] " + subject, Body = body, IsBodyHtml = false }; mail.To.Add("atsigma@gmail.com"); mail.ReplyToList.Add(new MailAddress(email, name)); smtp.Send(mail); // Show success banner alertSuccess.Visible = true; // Clear the form txName.Text = string.Empty; txEmail.Text = string.Empty; txSubject.Text = string.Empty; txMessage.Text = string.Empty; dropReason.SelectedIndex = 0; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Mail send error: " + ex.Message); } } } }