E-mail address check ! who can help me???or any advice

Z

zhang

what's the problem??

Remote_Addr = "hotmail.com"
sFrom = "<makefriend8@" & Remote_Addr + ">"

Dim oConnection As New TcpClient()
Try
oConnection.SendTimeout = 3000

oConnection.Connect(mserver, 25) ' msserver is right for
example mx4.HOTMAIL.COM

oStream = oConnection.GetStream()

sResponse = GetData(oStream)
sResponse = SendData(oStream, "HELO " & Remote_Addr & vbCrLf)
sResponse = SendData(oStream, "MAIL FROM: " & sFrom & vbCrLf)

If ValidResponse(sResponse) Then
sResponse = SendData(oStream, "RCPT TO: " & sTo & vbCrLf)

If ValidResponse(sResponse) Then
Return 1 'E-mail address is vaild
Else
Return 2 'wrong address
End If
End If

SendData(oStream, "QUIT" & vbCrLf)
oConnection.Close()
oStream = Nothing
Catch
Return 3 ' why go here?? no matter the address is right or
wrong.



Private Function GetData(ByRef oStream As NetworkStream) As String

Dim bResponse(1024) As Byte
Dim sResponse As String

Dim lenStream As Integer = oStream.Read(bResponse, 0, 1024)
If lenStream > 0 Then
sResponse = Encoding.ASCII.GetString(bResponse, 0, 1024)
End If
Return sResponse
End Function


Private Function SendData(ByRef oStream As NetworkStream, ByVal sToSend
As String) As String
Dim sResponse As String

Dim bArray() As Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)

oStream.Write(bArray, 0, bArray.Length())
sResponse = GetData(oStream)

Return sResponse
End Function


Private Function ValidResponse(ByVal sResult As String) As Boolean
Dim bResult As Boolean
Dim iFirst As Integer
If sResult.Length > 1 Then
iFirst = CType(sResult.Substring(0, 1), Integer)
If iFirst < 3 Then bResult = True
End If
Return bResult
End Function
 
P

Phillip Taylor

what's the problem??

Remote_Addr = "hotmail.com"
sFrom = "<makefriend8@" & Remote_Addr + ">"

Dim oConnection As New TcpClient()
Try
oConnection.SendTimeout = 3000

oConnection.Connect(mserver, 25) ' msserver is right for
example mx4.HOTMAIL.COM

oStream = oConnection.GetStream()

sResponse = GetData(oStream)
sResponse = SendData(oStream, "HELO " & Remote_Addr & vbCrLf)
sResponse = SendData(oStream, "MAIL FROM: " & sFrom & vbCrLf)

If ValidResponse(sResponse) Then
sResponse = SendData(oStream, "RCPT TO: " & sTo & vbCrLf)

If ValidResponse(sResponse) Then
Return 1 'E-mail address is vaild
Else
Return 2 'wrong address
End If
End If

SendData(oStream, "QUIT" & vbCrLf)
oConnection.Close()
oStream = Nothing
Catch
Return 3 ' why go here?? no matter the address is right or
wrong.

Private Function GetData(ByRef oStream As NetworkStream) As String

Dim bResponse(1024) As Byte
Dim sResponse As String

Dim lenStream As Integer = oStream.Read(bResponse, 0, 1024)
If lenStream > 0 Then
sResponse = Encoding.ASCII.GetString(bResponse, 0, 1024)
End If
Return sResponse
End Function

Private Function SendData(ByRef oStream As NetworkStream, ByVal sToSend
As String) As String
Dim sResponse As String

Dim bArray() As Byte = Encoding.ASCII.GetBytes(sToSend.ToCharArray)

oStream.Write(bArray, 0, bArray.Length())
sResponse = GetData(oStream)

Return sResponse
End Function

Private Function ValidResponse(ByVal sResult As String) As Boolean
Dim bResult As Boolean
Dim iFirst As Integer
If sResult.Length > 1 Then
iFirst = CType(sResult.Substring(0, 1), Integer)
If iFirst < 3 Then bResult = True
End If
Return bResult
End Function

Look at your code again....

sResponse = GetData(oStream)
sResponse = SendData(oStream, "HELO " & Remote_Addr &
vbCrLf)
sResponse = SendData(oStream, "MAIL FROM: " & sFrom &
vbCrLf)

If ValidResponse(sResponse) Then
sResponse = SendData(oStream, "RCPT TO: " & sTo &
vbCrLf)

If ValidResponse(sResponse) Then
Return 1 'E-mail address is vaild
Else
Return 2 'wrong address
End If
End If

SendData(oStream, "QUIT" & vbCrLf)
oConnection.Close()
oStream = Nothing
Catch
Return 3 ' why go here?? no matter the address is right
or
wrong.

--------If there is an error in this function, i.e sResult == Nothing
then it will throw an exception -------

Private Function ValidResponse(ByVal sResult As String) As Boolean
Dim bResult As Boolean
Dim iFirst As Integer
If sResult.Length > 1 Then
iFirst = CType(sResult.Substring(0, 1), Integer)
If iFirst < 3 Then bResult = True
End If
Return bResult
End Function

which makes the code jump straight to the catch block instantly. But
any line between the words TRY and CATCH that contain an error would
cause the application to jump straight to the catch.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top