0

need help!

Public Sub emailNotification(ByVal strTo As String, ByVal strFrom As String)

    Try
        If strTo Is Nothing Then
            MessageBox.Show("Please Check Email")
        Else
            Dim [to] As New MailAddress(strTo)
            Dim [from] As New MailAddress(strFrom)
            Dim message As New MailMessage([from], [to])

            message.Subject = "Parcel Info No: (" + txtTracking.Text + ")"
            message.Body = "You have received new Parcel. please collect at KK3 office. " + Environment.NewLine + Environment.NewLine + "KK3 System"

            Dim client As New SmtpClient("smtp.googlemail.com")
            client.Send(message)

        End If
    Catch ex As Exception
        Dim str As String = [String].Format("Exception caught in CreateTestMessage5(): {0} - {1}", ex.ToString(), ex.Message)

        MessageBox.Show(str)

    End Try

End Sub

Edited by mie.ilani

Attachments Untitled.png 182.64 KB
2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by Oxiegen
0

A string is rarely Nothing. But it can be empty.
Change the line If strTo Is Nothing Then to If String.IsNullOrEmpty(strTo) Then.
That should cover all the bases.

As a second thought, you should do the same for strFrom.
Include that in the If statement.

If String.IsNullOrEmpty(strTo) OrElse String.IsNullOrEmpty(strFrom) Then

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.