Problem sending email through gmail: the target machine activelyrefused it

A

Author

I have a SendMail method, which I have been using for a while. It
sends email by using my gmail account. It has been working perfectly
in my previous company.

Now I work for the government, and I am trying to re-use this method,
and it throws an exception which says:

<quote>
No connection could be made because the target machine actively
refused it 72.14.247.109:587
</quote>

I could ping 72.14.247.109, but telneting to this IP at port 587
failed. See details below. My c# code is also pasted at the end. I
googled a little, some people say that the firewall might be blocking
the request. But, I don't quite understand the logic here: It is
google, not my side, that is refusing the request, right?

C:\>ping 72.14.247.109

Pinging 72.14.247.109 with 32 bytes of data:

Reply from 72.14.247.109: bytes=32 time=17ms TTL=244
Reply from 72.14.247.109: bytes=32 time=21ms TTL=244
Reply from 72.14.247.109: bytes=32 time=16ms TTL=244
Reply from 72.14.247.109: bytes=32 time=16ms TTL=244

Ping statistics for 72.14.247.109:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 16ms, Maximum = 21ms, Average = 17ms

C:\>telnet 72.14.247.109 587
Connecting To 72.14.247.109...Could not open connection to the host,
on port 587
: Connect failed

// My C# code: SendMail
private static void SendMail(string fromAddress, string toAddress,
string ccAddress, string bccAddress, string subject, string
messageBody)
{
string smtpHost = "smtp.gmail.com";
int smtpPort = 587;
string smtpUserName = "my_user_name";
string smtpPassword = "my_password";
bool smtpUseSsl = true;
bool smtpUseDefaultCredentials = false;

MailMessage message = new MailMessage();
message.From = new MailAddress(fromAddress);
message.To.Add(new MailAddress(toAddress));

if (ccAddress.Length > 5)
{
message.CC.Add(new MailAddress(ccAddress));
}

if (bccAddress.Length > 5)
{
message.Bcc.Add(new MailAddress(bccAddress));
}
message.Subject = subject;
message.Body = messageBody;

System.Net.NetworkCredential cred = new
System.Net.NetworkCredential(smtpUserName, smtpPassword);
System.Net.Mail.SmtpClient mailClient = new
System.Net.Mail.SmtpClient(smtpHost, smtpPort);
mailClient.EnableSsl = smtpUseSsl;
mailClient.UseDefaultCredentials =
smtpUseDefaultCredentials;
mailClient.Credentials = cred;
mailClient.Send(message);
}
 
A

Author

I have a complete gmail working example at:http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!138.entry

download the code.  change a few settings, and it should work.

read the notes in the config file about the port number.

.....................

You can use my mini library as is, or at least figure out your issue.

Thanks. My code shown also works perfectly in a different
environment. I guess my question boils down to this: Will my local
firewall block my request to gmail? It does not quite make sense to
me. If not, then why is google refusing my request?
 
A

Author

Firewall is blocking port 587 if you can not telnet to it.

Thank you. Maybe this discussion will help me understand the issue.

Are you saying that for computer A to talk to port 587 of computer B,
computer A also needs to use its port number 587? It's been quite a
while since I coded a chat application in C long time ago when I was a
student.
 
A

Author

Thanks.  My code shown also works perfectly in a different
environment.  I guess my question boils down to this: Will my local
firewall block my request to gmail?  It does not quite make sense to
me.  If not, then why is google refusing my request?

Google is not refusing your request -- it is not getting through to Google.  (Cf. your Telnet example.)  587 is an unusual port and a firewall could be blocking it without causing other noticeable problems... inquire about the local firewalls.

Thanks. But one thing I don't understand is: Why is my local port
relevant in this situation? Does my computer need to use Port 587 to
talk to Port 587 of smtp.google.com?
 
A

Author

Thank you. Maybe this discussion will help me understand the issue.

Are you saying that for computer A to talk to port 587 of computer B,
computer A also needs to use its port number 587?  

Firewalls can block outbound as well as inbound traffic.  I'll bet somebody wanted to prevent spambots from reaching GMail.

Are you implying that my computer also needs to use its port number
587 in this situation? I am aware that a firewall can block both
inbound and outbound traffic.
 
A

Author

Are you implying that my computer also needs to use its port number
587 in this situation?  I am aware that a firewall can block both
inbound and outbound traffic.

As I understand it (and this is without a very firm grip on the situation) you are wanting to send data packets out with port number 587 and the other computer will receive them with port number 587.  As you know, a "port" is not a hardware device, but a label attached to the packets.

Thanks. I only know that I need to make this mail-sending request to
smtp.google.com:587. I am not sure if you so indicated, but I never
specified a localhost port number, which I think is irrelevant, but I
maybe wrong.

So, maybe for Computer A to talk to Port N of Computer B, by default,
Computer A would also be using the same port number, i.e., N, even if
a port number is usually not specified on the client side???

Someone out there please verify? People in this thread seem to be
stumped. At least no one has given me a clear YesOrNo or even a
YesAndNo answer.
 
K

Karl Mitschke

Hello Author,
Thanks. I only know that I need to make this mail-sending request to
smtp.google.com:587. I am not sure if you so indicated, but I never
specified a localhost port number, which I think is irrelevant, but I
maybe wrong.

So, maybe for Computer A to talk to Port N of Computer B, by default,
Computer A would also be using the same port number, i.e., N, even if
a port number is usually not specified on the client side???

Someone out there please verify? People in this thread seem to be
stumped. At least no one has given me a clear YesOrNo or even a
YesAndNo answer.

The "government" you work for is probally blocking access to gmail. (If they
have any brains they are)

Why should you be accessing gmail from a government computer?

Can you login to gmail using a web browser?

We block ALL external mail sources (gmail, hotmail, local ISP, etcetera)

Government employees are expected to do government work.

If your chat program is needed for government work, i am sure you can figure
out whom to contact for a waiver
 
A

Author

So, maybe for Computer A to talk to Port N of Computer B, by default,
Computer A would also be using the same port number, i.e., N, even if
a port number is usually not specified on the client side???

The port number is like an additional part of the IP address.  So in order for your computer to send a packet to port 587 of another computer, thepacket must be tagged for port 587, and your firewall must allow it to go out, and the other computer's firewall must allow it to come in.

More at:http://en.wikipedia.org/wiki/TCP_and_UDP_port

Like you, I hope others can tell us more about this.  Specifically, since SMTP is a two-way communication protocol (acknowledgements, etc., get sent back to you), do they come in on the same port number that they're sent out on?  I think so but am not sure.

I know what an IP and port number are. The thing I am not not sure is
as follows, which I have been repeating many times.

If my local host wants to talk to a remote computer through the remote
computer's port number n, is the port number n of my local host
participating in the communication? Well, in socket programming, I
think we only need to specify the remote host's port number, correct?

I guess most people here don't know about the low-level details of tcp-
ip communication or how a firewall works (I assume they are
essentially closely related anyway).
 
A

Author

Hello Author,







The "government" you work for is probally blocking access to gmail. (If they
have any brains they are)

Why should you be accessing gmail from a government computer?

Can you login to gmail using a web browser?

We block ALL external mail sources (gmail, hotmail, local ISP, etcetera)

Government employees are expected to do government work.

If your chat program is needed for government work, i am sure you can figure
out whom to contact for a waiver.

You must be kidding. :)

I can certainly login to gmail using a web browser. And how is the
chat program relevant in this case?

I need to use smtp.google.com service while I am testing my
application for error logging. I can easily request to have a test
email set up. But I am interested in learning why I cannot use this
gmail smtp service like I normally do.
 
F

Family Tree Mike

Author said:
I need to use smtp.google.com service while I am testing my
application for error logging. I can easily request to have a test
email set up. But I am interested in learning why I cannot use this
gmail smtp service like I normally do.

Have you tried to change your code to use the government email account and
server? This should not be a big change to your code presumably.
 
A

Author

Have you tried to change your code to use the government email account and
server?  This should not be a big change to your code presumably.

Yeah, I did and it works as expected, but I would like to learn what
is preventing me from using the smtp service of gmail.
 
J

Jeff Johnson

I know what an IP and port number are. The thing I am not not sure is
as follows, which I have been repeating many times.
If my local host wants to talk to a remote computer through the remote
computer's port number n, is the port number n of my local host
participating in the communication? Well, in socket programming, I
think we only need to specify the remote host's port number, correct?

I'm not an expert in TCP/IP programming, but here's what I understand:
Packets contain two addresses: the destination address and the "return
address." You can ask to talk to smtp.google.com:587 and tell the receiver
to respond to you on yourapp.yourdomain.com:23642. I believe that if you do
not specify a specific port for the return address then the outgoing port is
assumed (or is inserted automatically behind the scenes).

This is immaterial, however, to your issue. What matters is whether or not
your firewall will let ANY packet leave your box if that packet is addressed
to port 587. This is the first thing to check.
 
A

Author

I'm not an expert in TCP/IP programming, but here's what I understand:
Packets contain two addresses: the destination address and the "return
address." You can ask to talk to smtp.google.com:587 and tell the receiver
to respond to you on yourapp.yourdomain.com:23642. I believe that if you do
not specify a specific port for the return address then the outgoing portis
assumed (or is inserted automatically behind the scenes).

This is immaterial, however, to your issue. What matters is whether or not
your firewall will let ANY packet leave your box if that packet is addressed
to port 587. This is the first thing to check.

Yeah, that makes perfect sense. I guess the firewall here blocks any
unusual ports, be it inbound or outbound. I also notice that I cannot
RDC to a host outside the domain, although I can RDC to the remote
host from home.
 
J

J.B. Moreno

Author said:
Yeah, I did and it works as expected, but I would like to learn what
is preventing me from using the smtp service of gmail.

Since you've said that (a) it works from other machines when connecting
to gmail and (b) works from this machine when not connecting to gmail,
the most like answer is your organizational firewall.

If it's the firewall the solution is obvious -- talk to the admins and
find out how you request and get a waiver. Not knowing your code, it's
possible you have either a protocol problem or a missing assembly, but
I'd go with firewall as my first choice.
 
Top