The
application is simple but could easily be improved by validating each
of the required fields through the use of regular expressions or by at
least validating that the text associated with each of the text boxes
is not an empty string. To maintain the simplicity of the project,
little in the way of error handling has been included.
The following figure (Figure 1) shows a properly configured collection of input fields in use:

Figure 1: The Demonstration Application in Use
A
quick review of the code will reveal that there is little going on
there. The following imports were added to the top of the class:
Imports System
Imports System.Net.Mail
The
System.Net.Mail import brings in the support necessary to transmit the
messages generated using the application. Following the imports and
the class declaration, there is a declarations region identified and
within that region is a collection of private member variables; these
private member variables are created in order to supply each of the
required elements of the message.
#Region "Declarations"
' message elements
Private mMailServer As String
Private mTo As String
Private mFrom As String
Private mMsg As String
Private mSubject As String
#End Region
At this point, the only thing left to do in code is to write the following three methods:
#Region "Methods"
Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
' set up the carriers list - this is a fair list, you may wish to
' research the topic and add others, it took a while to generate this
' list...
cboCarrier.Items.Add("@itelemigcelular.com.br")
cboCarrier.Items.Add("@message.alltel.com")
cboCarrier.Items.Add("@message.pioneerenidcellular.com")
cboCarrier.Items.Add("@messaging.cellone-sf.com")
cboCarrier.Items.Add("@messaging.centurytel.net")
cboCarrier.Items.Add("@messaging.sprintpcs.com")
cboCarrier.Items.Add("@mobile.att.net")
cboCarrier.Items.Add("@mobile.cell1se.com")
cboCarrier.Items.Add("@mobile.celloneusa.com")
cboCarrier.Items.Add("@mobile.dobson.net")
cboCarrier.Items.Add("@mobile.mycingular.com")
cboCarrier.Items.Add("@mobile.mycingular.net")
cboCarrier.Items.Add("@mobile.surewest.com")
cboCarrier.Items.Add("@msg.acsalaska.com")
cboCarrier.Items.Add("@msg.clearnet.com")
cboCarrier.Items.Add("@msg.mactel.com")
cboCarrier.Items.Add("@msg.myvzw.com")
cboCarrier.Items.Add("@msg.telus.com")
cboCarrier.Items.Add("@mycellular.com")
cboCarrier.Items.Add("@mycingular.com")
cboCarrier.Items.Add("@mycingular.net")
cboCarrier.Items.Add("@mycingular.textmsg.com")
cboCarrier.Items.Add("@o2.net.br")
cboCarrier.Items.Add("@ondefor.com")
cboCarrier.Items.Add("@pcs.rogers.com")
cboCarrier.Items.Add("@personal-net.com.ar")
cboCarrier.Items.Add("@personal.net.py")
cboCarrier.Items.Add("@portafree.com")
cboCarrier.Items.Add("@qwest.com")
cboCarrier.Items.Add("@qwestmp.com")
cboCarrier.Items.Add("@sbcemail.com")
cboCarrier.Items.Add("@sms.bluecell.com")
cboCarrier.Items.Add("@sms.cwjamaica.com")
cboCarrier.Items.Add("@sms.edgewireless.com")
cboCarrier.Items.Add("@sms.hickorytech.com")
cboCarrier.Items.Add("@sms.net.nz")
cboCarrier.Items.Add("@sms.pscel.com")
cboCarrier.Items.Add("@smsc.vzpacifica.net")
cboCarrier.Items.Add("@speedmemo.com")
cboCarrier.Items.Add("@suncom1.com")
cboCarrier.Items.Add("@sungram.com")
cboCarrier.Items.Add("@telesurf.com.py")
cboCarrier.Items.Add("@teletexto.rcp.net.pe")
cboCarrier.Items.Add("@text.houstoncellular.net")
cboCarrier.Items.Add("@text.telus.com")
cboCarrier.Items.Add("@timnet.com")
cboCarrier.Items.Add("@timnet.com.br")
cboCarrier.Items.Add("@tms.suncom.com")
cboCarrier.Items.Add("@tmomail.net")
cboCarrier.Items.Add("@tsttmobile.co.tt")
cboCarrier.Items.Add("@txt.bellmobility.ca")
cboCarrier.Items.Add("@typetalk.ruralcellular.com")
cboCarrier.Items.Add("@unistar.unifon.com.ar")
cboCarrier.Items.Add("@uscc.textmsg.com")
cboCarrier.Items.Add("@voicestream.net")
cboCarrier.Items.Add("@vtext.com")
cboCarrier.Items.Add("@wireless.bellsouth.com")
End Sub
Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
' Collect user input from the form and stow content into
' the objects member variables
mTo = Trim(txtPhoneNumber.Text) &
Trim(cboCarrier.SelectedItem.ToString())
mFrom = Trim(txtSender.Text)
mSubject = Trim(txtSubject.Text)
mMailServer = Trim(txtMailServer.Text)
mMsg = Trim(txtMessage.Text)
' Within a try catch, format and send the message to
' the recipient. Catch and handle any errors.
Try
Dim message As New MailMessage(mFrom, mTo, mSubject, mMsg)
Dim mySmtpClient As New SmtpClient(mMailServer)
mySmtpClient.UseDefaultCredentials = True
mySmtpClient.Send(message)
MessageBox.Show("The mail message has been sent to " &
message.To.ToString(), "Mail", MessageBoxButtons.OK,
MessageBoxIcon.Information)
Catch ex As FormatException
MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,
MessageBoxIcon.Error)
Catch ex As SmtpException
MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,
MessageBoxIcon.Error)
Catch ex As Exception
MessageBox.Show(ex.StackTrace, ex.Message, MessageBoxButtons.OK,
MessageBoxIcon.Error)
End Try
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
' Upon user's request, close the application
Application.Exit()
End Sub
#End Region