Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO;
- using System.Net;
- using System.Net.Mail;
- using System.Net.NetworkInformation;
- using System.Collections;
- public class Test
- {
- public static ArrayList globalList;
- static void Main(string[] args)
- {
- //string bodydetails = "";
- double percent = 0;
- //int loop = 5;
- //while (loop < 5)
- string bodydetails = "";
- ArrayList globalList = new ArrayList();
- globalList.Add(bodydetails);
- Console.WriteLine(Environment.MachineName);
- {
- DriveInfo[] allDrives = DriveInfo.GetDrives();
- foreach (DriveInfo d in allDrives)
- {
- Console.WriteLine("Drive {0}", d.Name);
- Console.WriteLine(" Drive type: {0}", d.DriveType);
- if (d.IsReady == true)
- {
- Console.WriteLine(" Volume label: {0}", d.VolumeLabel);
- Console.WriteLine(" File system: {0}", d.DriveFormat);
- Console.WriteLine(
- " Available space to current user:{0, 15} bytes",
- d.AvailableFreeSpace, String.Format("Value: {0:P2}.", 0.100));
- //storage is binary not decimal
- Console.WriteLine(
- " Total available space: {0, 15} bytes",
- d.TotalFreeSpace);
- Console.WriteLine(
- " Total available space: {0, 15} Gigabytes",
- d.TotalFreeSpace / 1024m / 1024m / 1024m);
- Console.WriteLine(
- " Total size of drive: {0, 15} bytes ",
- d.TotalSize);
- /*long total = d.TotalSize;
- Console.WriteLine(
- " Total size = {0}", total);*/
- long half = 50 * d.TotalSize / 100;
- long quarter = 25 * d.TotalSize / 100;
- percent = (d.TotalFreeSpace / d.TotalSize) * 100;
- Console.WriteLine(
- " current percentage = {0}", percent);
- Console.WriteLine(
- " 50% = {0}", half);
- Console.WriteLine(
- " 25% = {0}", quarter);
- string drivelabel = d.VolumeLabel;
- bodydetails = Environment.MachineName + " " + d.Name + " on " + drivelabel + " has " + percent + "% remaining";
- }
- email(globalList, percent);
- }
- }
- }
- public static void email(ArrayList globalList, double percent)
- //public static void email(ArrayList content, string temp, Double percent)
- //public static void email(ArrayList content, string temp)
- {
- if (90 >= percent)
- {
- string myemailaddress = "email";
- //var fromAddress = new MailAddress("", "Name");
- var fromAddress = new MailAddress(myemailaddress, "name");
- //var fromAddress = myemailaddress;
- var toAddress = new MailAddress("email", "name");
- const string fromPassword = "password";
- const string subject = "Subject";
- //const string body = "your storage is more than half";
- //const string body = "percent";
- //string body = content.ToString();
- string body = globalList.ToString();
- Console.WriteLine(body);
- //string body = "{0}"
- //string body = "you have percent.ToString"();
- //string body = drivelabel + bodydetails+ Environment.MachineName + " has " + percent + "% remaining";
- //string body = content.ToString();
- //string body = bodydetails;
- var smtp = new SmtpClient
- {
- Host = "smtp.gmail.com",
- Port = 587,
- EnableSsl = true,
- DeliveryMethod = SmtpDeliveryMethod.Network,
- UseDefaultCredentials = false,
- Credentials = new NetworkCredential(fromAddress.Address, fromPassword)
- };
- using (var message = new MailMessage(fromAddress, toAddress)
- {
- Subject = subject,
- Body = body
- })
- {
- smtp.Send(message);
- }
- return;
- }
- {
- //ping();
- //Console.WriteLine("body");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement