Advertisement
Guest User

Untitled

a guest
May 8th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.58 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Net;
  4. using System.Net.Mail;
  5. using System.Net.NetworkInformation;
  6. using System.Collections;
  7.  
  8. public class Test
  9. {
  10. public static ArrayList globalList;
  11.  
  12. static void Main(string[] args)
  13. {
  14.  
  15. //string bodydetails = "";
  16. double percent = 0;
  17.  
  18. //int loop = 5;
  19. //while (loop < 5)
  20. string bodydetails = "";
  21. ArrayList globalList = new ArrayList();
  22. globalList.Add(bodydetails);
  23.  
  24.  
  25. Console.WriteLine(Environment.MachineName);
  26. {
  27. DriveInfo[] allDrives = DriveInfo.GetDrives();
  28.  
  29. foreach (DriveInfo d in allDrives)
  30.  
  31. {
  32. Console.WriteLine("Drive {0}", d.Name);
  33. Console.WriteLine(" Drive type: {0}", d.DriveType);
  34. if (d.IsReady == true)
  35. {
  36. Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
  37. Console.WriteLine(" File system: {0}", d.DriveFormat);
  38. Console.WriteLine(
  39. " Available space to current user:{0, 15} bytes",
  40. d.AvailableFreeSpace, String.Format("Value: {0:P2}.", 0.100));
  41. //storage is binary not decimal
  42. Console.WriteLine(
  43. " Total available space: {0, 15} bytes",
  44. d.TotalFreeSpace);
  45.  
  46. Console.WriteLine(
  47. " Total available space: {0, 15} Gigabytes",
  48. d.TotalFreeSpace / 1024m / 1024m / 1024m);
  49.  
  50. Console.WriteLine(
  51. " Total size of drive: {0, 15} bytes ",
  52. d.TotalSize);
  53.  
  54. /*long total = d.TotalSize;
  55.  
  56. Console.WriteLine(
  57. " Total size = {0}", total);*/
  58.  
  59. long half = 50 * d.TotalSize / 100;
  60. long quarter = 25 * d.TotalSize / 100;
  61. percent = (d.TotalFreeSpace / d.TotalSize) * 100;
  62.  
  63.  
  64. Console.WriteLine(
  65. " current percentage = {0}", percent);
  66. Console.WriteLine(
  67. " 50% = {0}", half);
  68. Console.WriteLine(
  69. " 25% = {0}", quarter);
  70.  
  71. string drivelabel = d.VolumeLabel;
  72. bodydetails = Environment.MachineName + " " + d.Name + " on " + drivelabel + " has " + percent + "% remaining";
  73.  
  74. }
  75. email(globalList, percent);
  76. }
  77. }
  78. }
  79.  
  80. public static void email(ArrayList globalList, double percent)
  81. //public static void email(ArrayList content, string temp, Double percent)
  82. //public static void email(ArrayList content, string temp)
  83.  
  84. {
  85. if (90 >= percent)
  86. {
  87. string myemailaddress = "email";
  88. //var fromAddress = new MailAddress("", "Name");
  89. var fromAddress = new MailAddress(myemailaddress, "name");
  90. //var fromAddress = myemailaddress;
  91. var toAddress = new MailAddress("email", "name");
  92. const string fromPassword = "password";
  93. const string subject = "Subject";
  94. //const string body = "your storage is more than half";
  95. //const string body = "percent";
  96. //string body = content.ToString();
  97. string body = globalList.ToString();
  98. Console.WriteLine(body);
  99. //string body = "{0}"
  100. //string body = "you have percent.ToString"();
  101. //string body = drivelabel + bodydetails+ Environment.MachineName + " has " + percent + "% remaining";
  102. //string body = content.ToString();
  103.  
  104. //string body = bodydetails;
  105.  
  106.  
  107. var smtp = new SmtpClient
  108. {
  109. Host = "smtp.gmail.com",
  110. Port = 587,
  111. EnableSsl = true,
  112. DeliveryMethod = SmtpDeliveryMethod.Network,
  113. UseDefaultCredentials = false,
  114. Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
  115. };
  116. using (var message = new MailMessage(fromAddress, toAddress)
  117. {
  118. Subject = subject,
  119. Body = body
  120. })
  121. {
  122. smtp.Send(message);
  123. }
  124. return;
  125. }
  126. {
  127. //ping();
  128. //Console.WriteLine("body");
  129. }
  130. }
  131. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement