Advertisement
Guest User

Untitled

a guest
Aug 9th, 2015
359
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. > System.Net.Mail.SmtpException: Failure sending mail. ---> System.IO.IOException: Unable to read data from the transport connection: net_io_connectionclosed.
  2. at System.Net.Mail.SmtpReplyReaderFactory.ProcessRead(Byte[] buffer, Int32 offset, Int32 read, Boolean readLine)
  3. at System.Net.Mail.SmtpReplyReaderFactory.ReadLines(SmtpReplyReader caller, Boolean oneLine)
  4. at System.Net.Mail.SmtpReplyReaderFactory.ReadLine(SmtpReplyReader caller)
  5. at System.Net.Mail.SmtpConnection.GetConnection(ServicePoint servicePoint)
  6. at System.Net.Mail.SmtpTransport.GetConnection(ServicePoint servicePoint)
  7. at System.Net.Mail.SmtpClient.GetConnection()
  8. at System.Net.Mail.SmtpClient.Send(MailMessage message)
  9. --- End of inner exception stack trace ---
  10. at System.Net.Mail.SmtpClient.Send(MailMessage message)
  11. at ConsoleApplication1.mail_core.sendMail() in c:UsersCybeXDocumentsVisual Studio 2013ProjectsConsoleApplication1ConsoleApplication1mail_core.cs:line 69
  12.  
  13. class mail_core
  14. {
  15. //Mail components
  16. static MailAddress from;
  17. static string sfrom;
  18. static string sto;
  19. static MailAddress to;
  20. static MailMessage newEmail;
  21.  
  22. //smtpServer
  23. SmtpClient SMTPServer;
  24. static string smtpServerAddress;
  25. static int smtpServerPort;
  26. static NetworkCredential cred;
  27. static bool ssl;
  28.  
  29. public mail_core() { }
  30.  
  31. public void NewMail(string recieverEmail, string recieverName, string senderEmail, string senderName, string subject, string message, string attachementFile)
  32. {
  33. sto = recieverEmail;
  34. sfrom = senderEmail;
  35. //to = new MailAddress(recieverEmail, recieverName);
  36. //from = new MailAddress(senderEmail, senderName);
  37. //newEmail = new MailMessage(from, to);
  38. //newEmail.Subject = subject;
  39. //newEmail.Body = message;
  40. newEmail = new MailMessage(sfrom, sto, subject, message);
  41. if (!attachementFile.Equals(""))
  42. {
  43. newEmail.Attachments.Add(new Attachment(attachementFile));
  44. }
  45. }
  46.  
  47. public void smtpServerSettings(string server, int port, string EmailUsername, string EmailPassword, bool sslEnable)
  48. {
  49. smtpServerAddress = server;
  50. smtpServerPort = port;
  51. cred = new NetworkCredential(EmailUsername, EmailPassword);
  52. ssl = sslEnable;
  53. }
  54.  
  55. public void sendMail()
  56. {
  57. bool sent = false;
  58. int count = 0;
  59. while (!sent)
  60. {
  61. count++;
  62. try
  63. {
  64. SMTPServer = new SmtpClient(smtpServerAddress);
  65. SMTPServer.Port = smtpServerPort;
  66. SMTPServer.UseDefaultCredentials = false;
  67. SMTPServer.Credentials = cred;
  68. SMTPServer.EnableSsl = ssl;
  69. SMTPServer.DeliveryMethod = SmtpDeliveryMethod.Network;
  70. SMTPServer.Send(newEmail);
  71. sent = true;
  72. }
  73. catch (Exception x)
  74. {
  75. Console.WriteLine(x);
  76. sent = false;
  77. }
  78. }
  79. Console.WriteLine("tried times: {0}",count);
  80. }
  81.  
  82. }
  83.  
  84. static void Main(string[] args)
  85. {
  86. mail_core temp = new mail_core();
  87. Console.WriteLine("ready?");
  88. Console.ReadLine();
  89. temp.NewMail("xyz@gmail.com", "xyz", "abc@rocketmail.com", "abc", "a test email", "this is my first test email", "");
  90. temp.smtpServerSettings("smtp.gmail.com", 465, "xyz@gmail.com", "2 step google verification password", true);
  91. Console.WriteLine("sending...");
  92. Console.WriteLine("=============================================================");
  93. temp.sendMail();
  94. Console.WriteLine("=============================================================");
  95. //if (temp.sendMail())
  96. //{
  97. // Console.WriteLine("Mail sent :DDDD");
  98. //}
  99. //else Console.WriteLine("Mail not sent :(((");
  100. Console.ReadLine();
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement