Advertisement
Guest User

Untitled

a guest
Sep 24th, 2015
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.54 KB | None | 0 0
  1. public static void HandlingMail(List<String> destEmails, String subject, String body)
  2. {
  3. System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage();
  4.  
  5.  
  6. foreach (String email in destEmails)
  7. {
  8. message.To.Add(email);
  9. }
  10.  
  11.  
  12. message.From = new System.Net.Mail.MailAddress("unknown@gmail.com");
  13.  
  14. message.Subject = subject;
  15.  
  16.  
  17. message.IsBodyHtml = true;
  18. message.Body = body;
  19.  
  20.  
  21. System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
  22. smtp.EnableSsl = true;
  23. smtp.Port = 587;
  24. smtp.Credentials = new System.Net.NetworkCredential("unknown@gmail.com", "password");
  25.  
  26.  
  27. try
  28. {
  29. smtp.Send(message);
  30. }
  31. catch (Exception ex)
  32. {
  33. Console.WriteLine(ex.StackTrace);
  34. Console.WriteLine(ex.Message);
  35. Console.WriteLine(ex.InnerException);
  36. }
  37. finally
  38. {
  39. message.Dispose();
  40.  
  41. }
  42. }
  43.  
  44.  
  45. // Here is the error
  46. //9/23/2015 8:50:53 PM at System.Net.Mail.SmtpClient.Send(MailMessage message)
  47. // at Program1.MailHandler.HandlingMail(List`1 destEmails, String subject, String body)
  48. // 9/23/2015 8:50:53 PM Failure sending mail.
  49. // 9/23/2015 8:50:53 PM System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: A socket operation was attempted to an unreachable network [2600:f8m0:4001:d06::9c]:587
  50. //at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress)
  51. //at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception)
  52. // --- End of inner exception stack trace ---
  53. //at System.Net.ServicePoint.GetConnection(PooledStream PooledStream, Object owner, Boolean async, IPAddress& address, Socket& abortSocket, Socket& abortSocket6)
  54. //at System.Net.PooledStream.Activate(Object owningObject, Boolean async, GeneralAsyncDelegate asyncCallback)
  55. //at System.Net.PooledStream.Activate(Object owningObject, GeneralAsyncDelegate asyncCallback)
  56. //at System.Net.ConnectionPool.GetConnection(Object owningObject, GeneralAsyncDelegate asyncCallback, Int32 creationTimeout)
  57. //at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
  58. //at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
  59. //at System.Net.Mail.SmtpClient.GetConnection()
  60. //at System.Net.Mail.SmtpClient.Send(MailMessage message)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement