Hi,
I followed the code as shown in MSDN example, but once I get to s.connect...nothing happens and after sometime it errors out saying not able to connect. Below is my code and let me know what exactly I am doing wrong
Public Shared Function Validate_Email_Address(ByVal inputEmail) As Boolean
Try
'Define those variables to be evaluated in the next for loop and
'then used to connect to the server. These variables are defined
'outside the for loop to make them accessible there after.
inputEmail =
"prem_rajani@yahoo.com"
Dim host As String() = (inputEmail.Split("@"c))
Dim hostname As String = host(1)
'Get DNS host information.
Dim IPhst As IPHostEntry = Dns.GetHostEntry("www." & hostname)
'Dim IPhst As IPHostEntry = Dns.GetHostEntry("www.yahoo.com")
'Evaluate the socket and receiving host IPAddress and IPEndPoint.
Dim endPt As New IPEndPoint(IPhst.AddressList(0), 25)
'Creates the Socket to send data over a TCP connection.
Dim s As New Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
'Connect to the host using its IPEndPoint.
s.Connect(endPt)
'Attempting to connect
If Not Check_Response(s, SMTPResponse.CONNECT_SUCCESS) Then
s.Close()
Return False
End If
'HELO server
Senddata(s,
String.Format("HELO {0}" & vbCr & vbLf, Dns.GetHostName()))
If Not Check_Response(s, SMTPResponse.GENERIC_SUCCESS) Then
s.Close()
Return False
End If
'Identify yourself
'Servers may resolve your domain and check whether
'you are listed in BlackLists etc.
Senddata(s,
String.Format("MAIL From: {0}" & vbCr & vbLf, "testexample@deepak.portland.co.uk"))
If Not Check_Response(s, SMTPResponse.GENERIC_SUCCESS) Then
s.Close()
Return False
End If
'Attempt Delivery (I can use VRFY, but most
'SMTP servers only disable it for security reasons)
Dim _To As String = inputEmail
Dim Tos As String() = _To.Split(New Char() {";"c})
For Each [To] As String In Tos
Senddata(s,
String.Format("RCPT TO: {0}" & vbCr & vbLf, [To]))
If Not Check_Response(s, SMTPResponse.GENERIC_SUCCESS) Then
s.Close()
Return False
End If
Next
'Senddata(s, address)
'If Not Check_Response(s, SMTPResponse.GENERIC_SUCCESS) Then
' s.Close()
' Return False
'End If
'Return (True)
Senddata(s,
"QUIT" & vbCr & vbLf)
Check_Response(s, SMTPResponse.QUIT_SUCCESS)
s.Close()
Return True
Catch ex As SocketException
Console.WriteLine(
"SocketException caught!!!")
Console.WriteLine((
"Source : " + ex.Source))
Console.WriteLine((
"Message : " + ex.Message))
Return False
Catch ex As ArgumentNullException
Console.WriteLine(
"ArgumentNullException caught!!!")
Console.WriteLine((
"Source : " + ex.Source))
Console.WriteLine((
"Message : " + ex.Message))
Return False
Catch ex As NullReferenceException
Console.WriteLine(
"NullReferenceException caught!!!")
Console.WriteLine((
"Source : " + ex.Source))
Console.WriteLine((
"Message : " + ex.Message))
Return False
Catch ex As Exception
Console.WriteLine(
"Exception caught!!!")
Console.WriteLine((
"Source : " + ex.Source))
Console.WriteLine((
"Message : " + ex.Message))
Return False
End Try
End Function