Solved

sending email via smtp

Posted on 2010-09-14
11
481 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
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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now