Click here to Skip to main content
15,891,253 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
In WindowsService C#, I'm trying to send email through service but it is giving an error saying that "unable to connect to the remote server" and sending failed. I tried with the different account types such as local service, local system, network and user but issue didnt resolved, and i also truned off windows fire wall settings,group policy but still issue remains the same. please help me out .

C#
try
{
  var client = new SmtpClient(smtp.gmail.com,587)
  {
      EnableSsl = true,
      Credentials = new NetworkCredential(mamise@gmail.com,passwd)
  }; 
  client.Send(rprise@gmail.com,girish@gmail.com,Test,Test);
}
Posted
Updated 26-Nov-13 0:50am
v2
Comments
ZurdoDev 26-Nov-13 7:36am    
I assume this is not the exact code as you don't have " " around your strings. However, the error is clear, you'll need to provide proper information to connect. I haven't done gmail so I don't know if port 587 is correct or not.
amshith 2-Dec-13 1:21am    
thank you

Verify that the credentials you are using to connect Gmail is correct. If it is correct then verify the port no for sending outgoing mails. I am not sure if the port no is 587. If you got everything correct and still not being able to send mail then try configuring the gmail account on outlook using the configurations you have and try sending mail.
 
Share this answer
 
Comments
amshith 2-Dec-13 1:22am    
The Gmail port number and client everything is correct and if i run the same piece of code in console project it works perfectly fine with no errors and also if i run the same code in the server using windows service also it works fine but the problem is with my laptop machine,I am not able to send emails using windows service in my laptop machine , I am the administrator of my machine, I'm not finding any solutions for this problem please please help me out.
Madhu Nair 2-Dec-13 2:13am    
Seems to be a firewall issue. Disable Firewall on your System and try sending mail. If still the issue persist then try disabling antivirus also.
You can also try checking their support page. There's also some troubleshooting steps that you may want to do.
From page:

If you tried configuring your SMTP server on port 465 (with SSL) and port 587 (with TLS), but are still having trouble sending mail, try configuring your SMTP to use port 25 (with SSL).

https://support.google.com/mail/answer/78775?hl=en[^]
 
Share this answer
 
Comments
amshith 2-Dec-13 1:23am    
The Gmail port number and client everything is correct and if i run the same piece of code in console project it works perfectly fine with no errors and also if i run the same code in the server using windows service also it works fine but the problem is with my laptop machine,I am not able to send emails using windows service in my laptop machine , I am the administrator of my machine, I'm not finding any solutions for this problem please please help me out.
walterhevedeich 2-Dec-13 1:55am    
Must be a config issue. Sorry but I cannot help you with that one since you mentioned that it worked on other platforms. I suggest you dig in through the errors. Maybe you can check the Event Viewer if there are other errors that may help in troubleshooting the issue.

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