如何检测mail服务器

时间:2021-05-31 18:09:32

 核心代码:

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim POPClient As New TcpClient(tx_pop.Text, 110)
        Status.Items.Clear()
        If tx_pop.Text.Trim = "" Or tx_smtp.Text.Trim = "" Then
            MessageBox.Show("Please input POP or SMTP SERVER ADDRESS")
            Exit Sub
        End If
        If tx_user.Text.Trim = "" Or tx_pass.Text.Trim = "" Then
            MessageBox.Show("Please input Your UserName or PASSWORD TO Login MailServer")
            Exit Sub
        End If
        Try
            NetStream = POPClient.GetStream()
            RdStrm = New StreamReader(POPClient.GetStream())
            Status.Items.Add(RdStrm.ReadLine())

            Data = "USER " + tx_user.Text + Chr(13) + Chr(10)
            SData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
            NetStream.Write(SData, 0, SData.Length)
            Status.Items.Add(RdStrm.ReadLine())

            Data = "PASS " + tx_pass.Text + Chr(13) + Chr(10)
            SData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
            NetStream.Write(SData, 0, SData.Length)
            Status.Items.Add(RdStrm.ReadLine())

            Data = "STAT" + Chr(13) + Chr(10)
            SData = System.Text.Encoding.ASCII.GetBytes(Data.ToCharArray())
            NetStream.Write(SData, 0, SData.Length)
            Status.Items.Add(RdStrm.ReadLine())
        Catch ex As Exception
            Status.Items.Add("Error: " + ex.ToString())
        End Try
    End Sub