Socket.Connect to SMTP to verify email always returns with smtp connection timeout - asp.net

I've written a tool that validates emails, mostly copied from various examples on the subject around on the internet (user Don Worthley compiled a decent collection of code samples here https://delicious.com/dworthley/email.validation). Unfortunately after creating the socket and the IPEndPoint from the email to verify's hostname IP and port, my code always fails to connect to the socket due to timeout.
Here is the pertinent code (fails at s.Connect(endPt) due to timeout):
private bool smtpCheckEmail(string email)
{
try
{
string[] host = (email.Split('#'));
string hostname = host[1];
IPHostEntry IPhst = Dns.GetHostEntry(hostname);
IPEndPoint endPt = new IPEndPoint(IPhst.AddressList[0], 25);
using (Socket s = new Socket(endPt.AddressFamily, SocketType.Stream, ProtocolType.Tcp))
{
try
{
s.Connect(endPt);
}
catch
{
s.Close();
return false;
}
From my research others have reported success with similar code so it might be an issue with my server host. The MVC project is on a GoDaddy VPS with Windows 7 and standard firewall/MSSE as protection (I've tested with both disabled with same timeout result).
I've verified I can telnet to my own host and run through the various HELO, Mail from etc commands but it also times out if I try to connect to smtp for other hosts.
Maybe it's an ISP issue?
I've also tried installing EmailVerify for .NET trial but run into the same problem where any validation at or above SMTP check times out.
Would be great to get some suggestions of what might be the problem and how to troubleshoot it.
Edit: After doing some comparison testing with one of my Azure VPS it looks like it is likely to be server related, "telnet 74.125.206.108 smtp" (gmail's smtp host IP) through command line connects on the Azure box but not on the GoDaddy one my project is on.
I also notice that when my code pulls the IP from the host name (Dns.GetHostEntry(hostname)), in this gmail example it returns 216.58.216.37 which matches what I get if a run nslookup in cmd for gmail.com, however the IP for smtp that I can telnet to is for gmail is 74.125.206.108 which matches the nslookup record for smtp.gmail.com. Could my code be grabbing the wrong IP addresses in many cases here?

Turned out to be a limitation of GoDaddy VPS. Transferred code to an Azure hosted project and it worked great.

Related

How to find if two distinct accounts are being accessed from same computer but using different browser?

I couldn't track a machine using ip-address because I usually get proxy server address
public static String GetIP()
{
String ip =
HttpContext.Current.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (string.IsNullOrEmpty(ip))
{
ip = HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];
}
return ip;
}
Are there any other ways to track a machine correctly?
Reading ip-address is the only way But with that also you can't trace exactly due to Network address translators,Proxy servers and VPN servers etc.
You have to understand this its privacy issue
Even in iOS also they have forbidden to read UDID right from iOS 7 as it infringes users privacy
Hope this solves your problem

JavaDB(Derby) - Connection refused using Network Server Controller in LAN

I'm new to java networking. My scenario here is 2 client computers are connecting to a server hosted in LAN. So I use NetworkServerControl API to start the host:
private static void startServer(){
try{
NetworkServerControl nsc = new NetworkServerControl(InetAddress.getByName("localhost"), 1527);
nsc.start(null);
}catch(Exception e){
JOptionPane.showMessageDialog(null, "Start network error : " + e.getMessage());
}
My questions are:
1) Is localhost accessible by computers in LAN?
- If yes, I tried to use ij to connect derby database in the server but it wrote connection refused. Anything I missed out?
ij: CONNECT 'jdbc:derby://localhost:1527/c:/app_db/' user 'xxx' password 'xxx';
- If no, what is the common approach should be used? Please guide me the right track.
Thanks.
To access your Derby database from other machines on the network, you need to change "localhost" to a different value. You can give the DNS name of your machine, or the public IP address of your machine.
Note that you have to make this change both on the Derby server and on each of the client URLs.
You should be able to use netstat -a to confirm the effects of your changes on the server.

Unable to connect to any of the specified MySQL hosts issue in Production Environment

I was looking in posts similar to mine, but didn't find any response to my issue.
Recently the MySql server was changed, right now I'm using a different one,
I use this connection string in my asp.net vb web application project:
<add key="MySQLConnStr" value="server=xx.xxx.x.xx; user id=mysql_link; database=mysql; pooling=false; password=xxxx"/>
Ok when I run the WebApp in my computer (development environment) it works perfect, now, in the host (production env.) I get the "Unable to connect..." error.
What could be the problem here??? I just changed the old MySql server ip for the new one.
I restarted the application pools in the host, restarted the webapp as well, but nothing.
thanks in advance!
Is it possible that your MySql runs on different port number?.
(any port different from the default 3306)
If so, add to your connection string "Port=xxxx;"
EDIT: It's also possible that your MySql Administrator has not given to the ip address/name of your server the permission to connect whilst has given them to your local pc
complete connection string in c# code ..
public MySqlConnection con = new MySqlConnection("server=localhost;userid=root;password=XXXX;database=yourDBname;Port=XXXX");
Thanks

Cannot get user IP address (proxy/firewall/load balancer)

I used code below to get client ip with asp.net before but after I moved to VDS this function begin returning only my subnet mask which is 178.18.198.1 or 178.18.198.2.
Can anyone help me with this problem?
Private Function GetIPAddress() As String
Dim sIPAddress As String = Nothing
sIPAddress = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If String.IsNullOrEmpty(sIPAddress) Then
sIPAddress = Request.ServerVariables("REMOTE_ADDR")
End If
Return sIPAddress
End Function
EDIT
Found similar problem here:
Have deployed many 2008 32 bit
standard web servers using the citrix
netscaler isapi (the netscaler being a
load balancer), in all cases the
client IP address is logged in the
standard IIS logs. On a new project I
was asked to deploy 2008 R2,
configured IIS 7.5 identically with
how I configured IIS 7.0 in the past,
this time however the client ip is
returning the load balancer address in
the logs. Here is the weird part, I
installed "advanced logging" and it is
showing the client IP address
properly, so the isapi is doing its
job. Have googled this one to death
and could use some advice.
I also found ISAPI Filter module but cannot make it work: devcentral.f5.com/x_forwarded_for_log_filter_for_windows_servers
Problem solved by using HTTP_CLIENT_IP instead of REMOTE_ADDR in sourcecode files.
The problem about IIS Logs was solved by installing IIS Advanced Logging module as suggested here. Also I got error "503: Service Unavailable" after installing Advanced Logging but solved this by granting read-write permissions to Everyone for Program Files\IIS folder and started failed application pools.
http://kb.parallels.com/6735
Another solution suggested here is:
On the NetScaler under "load
balancing", "Services" then under the
advanced tab, under settings, check
the box for "Use Source IP" and
"Client IP" then in the Header field
"CLIENT-IP"
I use
IP.Text = Request.UserHostAddress;
In C#. Does that work for you?

Invalid URI for Localhost

We have a website/webservice running on one of our servers. We hit that webservice once a day with a scheduled .bat scipt.
Just recently the scheduled task started to fail. The log shows "Invalid URI: The hostname could not be parsed."
When we're logged into the server we can reach the website through http://localhost/website, but get an Invalid URI error when we hit the webservice http://localhost/website/ws.asmx.
Any ideas?
Edit:
We'be tried using the servername, the ipaddress, and port numbers (and combinations therein). Any other ideas?
For the private IP Address your using Wikipedia Reference http://en.wikipedia.org/wiki/IP_address for what are the limits and proper uses.
If you have access to the source code for the web service look for fixed IP Address being used along with having correct Server Bindings for using the service.
Try using the IP Address of the machine instead of localhost.
Basically, I'm taking a wild stab that someone ran a lockdown or a service patch was installed that somehow is filtering request resposes to localhost (127.0.0.1).
Try using the machine name instead of localhost

Resources