Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

sending email via smtp

Posted on 2010-09-14
11
Medium Priority
?
487 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:Michel Sakr
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 2000 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

926 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