Contact Form
Overview
A contact form demonstrating how to use the ASP.Net MailMessage object and the Exigo SMTP to send emails from your applications.
Namespaces
The following sample requires these namespaces:
using System.Net.Mail;
jQuery
We use jQuery UI Themes for styling.
<link href="<%=this.ResolveUrl("../../Themes/start/jquery-ui.custom.css") %>" rel="stylesheet" type="text/css" /> <script src="<%=this.ResolveUrl("../../Scripts/jquery.min.js") %>" type="text/javascript"></script> <script src="<%=this.ResolveUrl("../../Scripts/jquery-ui.min.js") %>" type="text/javascript"></script>
Submit The Form
This contact form collects the user's information and sends it in an email message.
// Configure our message's details MailAddress recipientEmail = new MailAddress(txtRecipientEmail.Text); MailAddress fromEmail = new MailAddress(txtEmail.Text); MailAddress replyToEmail = new MailAddress(txtEmail.Text); // Credentials used to send mail through SMTP SmtpClient smtp = new SmtpClient(SMTPServerUrl, SMTPServerPort); smtp.Credentials = new System.Net.NetworkCredential(SMTPServerLoginName, SMTPServerPassword); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; smtp.EnableSsl = SMTPSecureConnectionRequired; // Create the MailMessage object MailMessage message = new MailMessage(fromEmail, recipientEmail); message.Priority = MailPriority.Normal; message.ReplyToList.Add(replyToEmail); message.Sender = fromEmail; message.IsBodyHtml = true; message.Subject = "Request for more info"; message.Body = string.Format(@" This user has requested more info.<br /> <br /> First Name: {0}<br /> Last Name: {1}<br /> Contact Phone #: {2}<br /> Email: {3}<br /> <br /> Comments: {4}", txtFirstName.Text, txtLastName.Text, txtPhone.Text, txtEmail.Text, txtComment.InnerText); // Send the email smtp.Send(message);