Solved

sending email via smtp

Posted on 2010-09-14
11
485 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
RHCE - Red Hat OpenStack Prep Course

This course will provide in-depth training so that students who currently hold the EX200 & EX210 certifications can sit for the EX310 exam. Students will learn how to deploy & manage a full Red Hat environment with Ceph block storage, & integrate Ceph into other OpenStack service

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

623 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