This Verifys The email Id is Present or Not The Provided Address .
Using the code
The Folowing is Whole Code
Imports System
Imports System.Diagnostics
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.IO
Imports System.Text.RegularExpressions
Imports System.Web
Imports Microsoft.VisualBasic.Strings
Public Class Form1
Public Function ChatMailServer(ByVal sEmail As String) As Long
Dim oStream As NetworkStream
Dim sFrom As String
Dim sTo As String
Dim tResponse As Integer
Dim ConnectUP As Integer
Dim sResponse As String
Dim iResponse As Integer
Dim sToSend As String
Dim Remote_Addr As String
Dim mserver As String
Dim sText As String()
sTo = "<" + sEmail + ">"
'sperate domain name from user name
sText = sEmail.Split(CType("@", Char))
mserver = NSLookup(sText(1))
'If mail server is blank then fail
If mserver = "" Then
Return 4
Exit Function
End If
'Needs to be a valid domain name
Remote_Addr = "Rajshri.com"
sFrom = "<myIP@" & Remote_Addr + ">"
'Create Object as late as possible
Dim oConnection As New TcpClient()
Try
'Set connection based on load
oConnection.SendTimeout = 3000
'Connecting on SMTP port
oConnection.Connect(mserver, 25)
'Get Stream from Mailserver
oStream = oConnection.GetStream()
'Collect Response
sResponse = GetData(oStream)
sResponse = TalkToServer(oStream, "HELO " & Remote_Addr & vbCrLf)
sResponse = TalkToServer(oStream, "MAIL FROM: " & sFrom & vbCrLf)
If ValidResponse(sResponse) Then
sResponse = TalkToServer(oStream, "RCPT TO: " & sTo & vbCrLf)
If ValidResponse(sResponse) Then
Return 1
Else
Return 2
End If
End If
TalkToServer(oStream, "QUIT" & vbCrLf)
oConnection.Close()
oStream = Nothing
Catch
Return 3
End Try
End Function
#Region "Utilitiy"
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
Private Function TalkToServer(ByVal oStream As NetworkStream, ByVal sToSend As String) As String
Dim sresponse As String
sresponse = SendData(oStream, sToSend)
Return sresponse
End Function
'This Function fires off a NS lookup and uses a regx expression to find the server
'This idea was from a posting off the microsoft newsgroups
Private Function NSLookup(ByVal sDomain As String) As String
Dim info As New ProcessStartInfo()
info.UseShellExecute = False
info.RedirectStandardInput = True
info.RedirectStandardOutput = True
info.FileName = "nslookup"
info.Arguments = "-type=MX " + sDomain.ToUpper.Trim
Dim ns As Process
ns = Process.Start(info)
Dim sout As StreamReader
sout = ns.StandardOutput
Dim reg As Regex = New Regex("mail exchanger = (?<server>[^\\\s]+)")
Dim mailserver As String
Dim response As String = ""
Do While (sout.Peek() > -1)
response = sout.ReadLine()
Dim amatch As Match = reg.Match(response)
Debug.WriteLine(response)
If (amatch.Success) Then
mailserver = amatch.Groups("server").Value
Exit Do
End If
Loop
Return mailserver
End Function
#End Region
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
ChatMailServer(TextBox1.Text)
If ChatMailServer(TextBox1.Text) = "1" Then
MessageBox.Show("User is present")
Else
MessageBox.Show("Either User or Server Is Not There")
End If
End Sub
End Class