Problems trying to send email via smtp server

Asked

Viewed 1,164 times

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);
  • 1

    You’ve already released access to less secure apps in Gmail?

  • Yes, buddy. I’ve already cleared access to the less secure apps :(

  • 1

    So the problem is, as you said, the proxy.

  • I set an exception for smtp.gmail.com, but it also didn’t work. Is there any other configuration required?

  • 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.

  • have tried using port 465?

  • Yes, @Marconciliosouza. But it didn’t work either.

  • 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.

  • http://www.mimekit.net/docs/html/T_MailKit_Net_Smtp_SmtpClient.htm

  • @Leandor, managed to solve?

  • @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!!!

Show 6 more comments

1 answer

1


I was able to solve the problem through the people who manage the company’s network. They said that the server was blocking.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.