2
I am developing an application which sends emails via smtp.gmail.com server.
When I am connected to a common network, it works perfectly. But, by the network of my company occurs the following error:
System.Net.Webexception: Unable to connect to remote server --> System.Net.Sockets.Socketexception: An attempt to connect failed because the connected component did not respond to a match after a period of time or the established connection failed to host the connected host did not respond 64.233.186.108:587 r n in System.Net.Sockets.Socket.Doconnect(EndPoint endPointSnapshot, SocketAddress socketAddress)\r\n em System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)r n --- End of stack tracking of internal exceptions --- r n in System.Net.Servicepoint.Getconnection(Pooledstream Pooledstream, Object Owner, Boolean async, Ipaddress& address, Socket& abortSocket, Socket& abortSocket6) r n in System.Net.Pooledstream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)\r\n em System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)\r\n em System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)\r\n em System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)\r\n em System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)r n in System.Net.Mail.SmtpClient.Getconnection() r n in System.Net.Mail.SmtpClient.Send(Mailmessage message message)"
I am using port 587 and left Enablessl = true
This may be because of the company’s network proxy?
Follow the code section responsible for the settings:
MailMessage mensagemEmail = new MailMessage();
mensagemEmail.From = new MailAddress(Remetente, "Novo Registro");
mensagemEmail.Subject = Assunto;
mensagemEmail.Body = enviaMensagem;
mensagemEmail.IsBodyHtml = true;
SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
client.EnableSsl = true;
NetworkCredential cred = new NetworkCredential(StringsProjeto.remetente, StringsProjeto.pass);
client.Credentials = cred;
client.Send(mensagemEmail);
You’ve already released access to less secure apps in Gmail?
– Jéf Bueno
Yes, buddy. I’ve already cleared access to the less secure apps :(
– Leandro
So the problem is, as you said, the proxy.
– Jéf Bueno
I set an exception for smtp.gmail.com, but it also didn’t work. Is there any other configuration required?
– Leandro
I have no idea, nor do I know what kind of proxy/ firewall is used there. It has to do with who set up the network.
– Jéf Bueno
have tried using port 465?
– Marco Souza
Yes, @Marconciliosouza. But it didn’t work either.
– Leandro
I’ve had this problem sending email to a client, and the only way was using a third-party library. the problem occurred due to the type of security and only accepted STARTTLS, I used the Mailkit https://www.nuget.org/packages/MailKit/ see if it helps.
– Marco Souza
http://www.mimekit.net/docs/html/T_MailKit_Net_Smtp_SmtpClient.htm
– Marco Souza
@Leandor, managed to solve?
– Pablo Tondolo de Vargas
@Pablovargas, I did it! It was through the staff who manages the company’s network. They said the server was blocking it anyway. Thanks for the suggestions. Abs!!!
– Leandro