Guest User

Untitled

a guest
Sep 17th, 2018
700
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.47 KB | None | 0 0
  1. C# error in sending mail : A connect request was made on an already connected socket
  2. using (MailMessage mail = new MailMessage())
  3. {
  4. using (SmtpClient mailer = new SmtpClient("smtp.server.com"))
  5. {
  6. Console.Write("Sending mails...");
  7. mail.From = new MailAddress("from@mail.com");
  8. mail.To.Add("myaddress@mail.com");
  9. mail.Subject = "test-subject";
  10. mail.Body = "test-body";
  11. mailer.Port = 25;
  12. mailer.Credentials = new System.Net.NetworkCredential("from@mail.com", "from-password");
  13. mailer.EnableSsl = true;
  14. try
  15. {
  16. mailer.Send(mail);
  17. Console.WriteLine("Mail sent");
  18. }
  19. catch (Exception e)
  20. {
  21. Console.ForegroundColor = ConsoleColor.Red;
  22. Console.WriteLine("rCannot send mail, an error occured : {0}", e);
  23. Console.ResetColor();
  24. }
  25. }
  26. }
  27.  
  28. Cannot send mail, an error occured : System.Net.Mail.SmtpException: Failure sending mail. ---> System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A connect request was made on an already connected socket 200.200.200.200:25
  29. at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
  30. at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
  31. --- End of inner exception stack trace ---
  32. at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
  33. at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
  34. at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
  35. at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
  36. at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
  37. at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
  38. at System.Net.Mail.SmtpClient.GetConnection()
  39. at System.Net.Mail.SmtpClient.Send(MailMessage message)
  40. --- End of inner exception stack trace ---
  41. at System.Net.Mail.SmtpClient.Send(MailMessage message)
  42. at TestApp.Program.Main(String[] args) in D:DesktopTestAppTestAppProgram.cs:line 290
Add Comment
Please, Sign In to add comment