Solved

sending email via smtp

Posted on 2010-09-14
11
478 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
 
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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 69

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

758 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

24 Experts available now in Live!

Get 1:1 Help Now