The basic contact form you would create would only have a text box for comments. However, you could also have a dropdownlist for the user to choose a subject, etc. The last thing you would need is a button, which, in it’s click event will have the code necessary to send the email.

The first thing you want to do is to import the mail namespace in .Net:

using System.Net.Mail
Imports System.Net.Mail

Here’s the basic code for the button click event handler, which is necessary for sending the email.

Dim Msg as MailMessage=New MailMessage()
Dim MailObj as new SmtpClient("")
Msg.To.Add(new MailAddress(yourEmailAddress))
Msg.From = new MailAddress(yourEmailAddress)
Msg.Subject = "Subject of Email"
Msg.Body = YourTextBox.Text
Msg.IsBodyHTML = false
MailMessage Msg = new MailMessage();
SmtpClient MailObj = new SmtpClient("");
Msg.To.Add(new MailAddress(yourEmailAddress));
Msg.From = new MailAddress(yourEmailAddress);
Msg.Subject = "Subject of Email";
Msg.Body = YourTextBox.Text;
Msg.IsBodyHTML = false;

For the subject line, if you have a DropDownList for a subject line, you’d substitute the selected item as the subject (Msg.Subject)

If you needed a CC or BCC, you’d follow the same general form of the ‘To’ property:


Msg.CC.Add(new MailAddress(CCEmailAddress);
Msg.BCC.Add(new MailAddress(BCCEmailAddress);

It’s the same for VB.Net, without the semi-colons.

Since this is a contact form for users to send emails to you, most likely, you’d use your own email address for both the FROM and TO email addresses.

But that’s all there is – – put this in your button’s click event handler and you’re on your way to your first Contact form!