Click here to Skip to main content
15,888,097 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

When trying to send an email using gmails SMTP server I get the following error:

"Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 173.194.67.108 (173.194.67.108:587), connect timeout"

My code is as follows:

C#
System.Net.Mail.MailMessage email = new System.Net.Mail.MailMessage();

                email.To.Add(new MailAddress("User_To"));
                email.From = new MailAddress("User_From");
                email.Subject = "Question";
                email.Body = "Boody";

                SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
                client.EnableSsl = true;
                client.DeliveryMethod = SmtpDeliveryMethod.Network;

                client.UseDefaultCredentials = false;
                client.Credentials = new NetworkCredential("myGmailAccountEmail", "myGmailAccountPassword");
                client.Send(email);
Posted
Comments
Herman<T>.Instance 8-Feb-12 5:28am    
did you read this?
biki66 8-Feb-12 5:34am    
Yeah I found the article helpful but this is when i first got the error. I just tried pinging gmails smtp server from comand prompt which timed out so feel this is what is causing my error in code.
Richard MacCutchan 8-Feb-12 6:19am    
It seems that you do not have a network connection for some reason. I can connect to the smtp server from my home PC with no problems.

C#
MailAddress mailfrom = new MailAddress ( "frommail@gmail.com" );
            MailAddress mailto = new MailAddress ( "tomail@gmail.com" );
            MailMessage newmsg = new MailMessage ( mailfrom, mailto );

            newmsg.Subject = "Subject of Email";
            newmsg.Body = "Body(message) of email";

            ////For File Attachment, more file can also be attached

            //Attachment att = new Attachment ( "G:\\code.txt" );
            //newmsg.Attachments.Add ( att );

            SmtpClient smtps = new SmtpClient ( "smtp.gmail.com", 587 );
            smtps.UseDefaultCredentials = false;
            smtps.Credentials = new NetworkCredential ( "mail@gmail.com", "pwd" );
            smtps.EnableSsl = true;
            smtps.Send ( newmsg );
 
Share this answer
 
v2
Comments
uspatel 8-Feb-12 5:32am    
Pre tag added...
biki66 8-Feb-12 5:35am    
Thanks for posting. Unfortunately I get the same error. I failed in trying to ping gmails smtp from comand prompt.
use
C#
SmtpClient client = new SmtpClient("smtp.gmail.com");

instead of
C#
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
 
Share this answer
 
Please check the following url,

Send mail using Google Apps[^]

If you are sending email from gmail or google apps than all sent email would be store in the sent items of the gmail.
Hope this may help you...
 
Share this answer
 
Hi,

Thanks all for your posts, I have resolved this for now by using a SMTP server but I believe the issue to be network related as a friend is able to ping the server from his machine.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900