title: Object reference not set to an instance of an object while sending email VB.NET
body: <p>I want to an email message Application</p>
  
  <p>I used new keyword but still the problem exist. </p>
  
  <pre><code>Imports System.Net.Mail
  Public Class Form1
    Private myMsg As MailMessage
    Private smtpSender As SmtpClient
    Private Sub CreateMessage()
        myMsg.From = New MailAddress(txtForm.Text.Trim)
        myMsg.To.Add(txtTo.Text.Trim)
        myMsg.Subject = txtSubject.Text
        myMsg.Body = txtBody.Text
        myMsg.Priority = MailPriority.Normal
    End Sub
    Private Sub createSmtp()
        smtpSender.Credentials = New Net.NetworkCredential(txtForm.Text.Trim, txtPass.Text.Trim)
        smtpSender.EnableSsl = True
        smtpSender.Host = "smtp.live.com"
        smtpSender.Port = "587"
    End Sub
    Private Sub sendMessage()
        Try
            smtpSender.Send(myMsg)
        Catch ex As Exception
            MessageBox.Show(ex.ToString())
        End Try
    End Sub
    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
        CreateMessage()
        createSmtp()
        sendMessage()
    End Sub
  
    Private Sub btnResetField_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnResetField.Click
        txtBody.Clear()
        txtForm.Clear()
        txtPass.Clear()
        txtSubject.Clear()
        txtTo.Clear()
    End Sub
  End Class
  </code></pre>
  
  <p>Error in this line: <code>myMsg.From = New MailAddress(txtForm.Text.Trim)</code></p>