Solved

sending email via smtp

Posted on 2010-09-14
11
483 Views
Last Modified: 2012-06-27
Hi,

I am having a weird issue. Last night I did a piece of code to send email via Gmail smtp server and it worked ok from my home. However, I found this does not work in office this morning.

I followed all the settings information provided by Google(see the link below):
http://mail.google.com/support/bin/answer.py?hl=en&answer=13287

I also 'telnet' the port 465 on smtp.gmail.com in command window and it successfully connected. But if I tried to send email from .net code, it always end up with exception 'System.Net.Mail.SmtpException: The operation has timed out. at System.Net.Mail.SmtpClient.Send(MailMessage message) '.

my code is as below:

any idea, guys? not sure if my office computer has any setting problem or our company network has any rule to stop this working

Thanks
private void SendEmail()
        {
            try
            {
                var message = new MailMessage("yingtuo@gmail.com", "yingtuo@hotmail.com", "mail to myself", "empty body");
                var smtp = new SmtpClient();
                smtp.Host = "smtp.gmail.com";
                smtp.EnableSsl = true;
                smtp.Credentials = new NetworkCredential("yingtuo@gmail.com", "xxxxxxx");
                smtp.Port = 465;
                smtp.Send(message);
            }
            catch (Exception ex)
            {
                Response.Write(ex.ToString());
            }
        }

Open in new window

0
Comment
Question by:viola123
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
11 Comments
 
LVL 20

Expert Comment

by:Silvers5
ID: 33678462
is it the same machine you are sending from? any anti virus heurestic scan/interception that might block the sending? as it might think a trojan or a virus is doing it..
0
 
LVL 6

Expert Comment

by:ajb2222
ID: 33678534
my work computer blocks smtp from it unless the program is a specific name.  You need to talk to your network guys.
0
 
LVL 6

Author Comment

by:viola123
ID: 33678644
Hi, Silvers:

not the same machine. Last night it worked on my home laptop. today i tested the same code on the desktop computer in office but it does not work.

Thanks
0
Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

 
LVL 6

Author Comment

by:viola123
ID: 33678671
Hi, guys:

I am using McAfee as the anti-virus on my office computer. don't see any option to turn it off, but I already disabled all the running features of McAfee, but still not working.

thx
0
 
LVL 6

Author Comment

by:viola123
ID: 33678685
btw, my local firewall is turned off
0
 
LVL 14

Expert Comment

by:existenz2
ID: 33679712
Is smtp.google.com usable from external sites? I don't think it is and that you will need to use your local isp smtp server.
0
 
LVL 6

Author Comment

by:viola123
ID: 33681964
hi, existenz2:

smtp.gmail.com is a free public server for all external site. My code worked from home but not from office.

thanks
0
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 33682358
is port 465 open on your office firewall?
0
 
LVL 7

Expert Comment

by:Element1910
ID: 33687835
Aloha viola123,
Most companies/offices, try to block DNS entries but not IP entries. Here's a couple options:

1. Open the command prompt at your office computer and type 'ping smtp.gmail.com' and see if you get a response.
1a. If you don't get a reply back then at least the DNS entry is being blocked on your office network.
2. Try the IP address of the GMail SMTP server instead of smtp.gmail.com, in your code. It should be: 74.125.127.109

Let me know if either of these work.

Mahalo,
JP
0
 
LVL 6

Author Comment

by:viola123
ID: 33688114
Hi, Element1910:

1. i tried 'ping smtp.gmail.com' but could not get response
2. i tried smtp.Host = "74.125.127.109";  but still does not work

Thanks
0
 
LVL 7

Accepted Solution

by:
Element1910 earned 500 total points
ID: 33705080
Aloha again viola,

That means that the IP and DNS entry is being blocked at your office network. If the same code works at home, then the office network is the culprit - not your code :)

It's good news and bad news I guess.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question