Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- C# error in sending mail : A connect request was made on an already connected socket
- using (MailMessage mail = new MailMessage())
- {
- using (SmtpClient mailer = new SmtpClient("smtp.server.com"))
- {
- Console.Write("Sending mails...");
- mail.From = new MailAddress("from@mail.com");
- mail.To.Add("myaddress@mail.com");
- mail.Subject = "test-subject";
- mail.Body = "test-body";
- mailer.Port = 25;
- mailer.Credentials = new System.Net.NetworkCredential("from@mail.com", "from-password");
- mailer.EnableSsl = true;
- try
- {
- mailer.Send(mail);
- Console.WriteLine("Mail sent");
- }
- catch (Exception e)
- {
- Console.ForegroundColor = ConsoleColor.Red;
- Console.WriteLine("rCannot send mail, an error occured : {0}", e);
- Console.ResetColor();
- }
- }
- }
- 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
- at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
- at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout, Exception& exception)
- --- End of inner exception stack trace ---
- at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6, Int32 timeout)
- at System.Net.PooledStream.Activate(Object owningObject, Boolean async, Int32 timeout, GeneralAsyncDelegate asyncCallback)
- at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
- at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
- at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
- at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
- at System.Net.Mail.SmtpClient.GetConnection()
- at System.Net.Mail.SmtpClient.Send(MailMessage message)
- --- End of inner exception stack trace ---
- at System.Net.Mail.SmtpClient.Send(MailMessage message)
- at TestApp.Program.Main(String[] args) in D:DesktopTestAppTestAppProgram.cs:line 290
Add Comment
Please, Sign In to add comment