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;
- string bodydetails = "";
- ArrayList globalList = new ArrayList();
- 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 = ((double)d.TotalFreeSpace / (double)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";
- globalList.Add(bodydetails);
- }
- }
- //globalList.Add(bodydetails);
- }
- htmlbody(globalList, percent, bodydetails);
- }
- public static void htmlbody(ArrayList globalList, double percent, string bodydetails)
- {
- string body = string.Empty;
- //string line = "replacementLine";
- using (StreamReader reader = new StreamReader(("diskdiaghtml.html")))
- {
- body = reader.ReadToEnd();
- body = body.Replace("{userName}", bodydetails);
- //body = body.Replace("{userName}", bodydetails);
- //body = body.Replace("{percent}", );
- //body = body.Replace("{title}", "testline1");
- //body = body.Replace("{url}", "testline2");
- //body = body.Replace("{description}", "testline3");
- Console.WriteLine(body);
- //return body;
- //bodystring(body);
- email(globalList, percent, bodydetails, body, reader);
- }
- }
- public static void email(ArrayList globalList, double percent, string bodydetails, string body, StreamReader reader)
- {
- if (90 >= percent)
- {
- string myemailaddress = "Fromemail@gmail.com";
- var fromAddress = new MailAddress(myemailaddress, "FromName");
- var toAddress = new MailAddress("toemail@gmail.com", "del");
- const string fromPassword = "password";
- const string subject = "Subject";
- //string body = globalList.ToString();
- //string body = reader;
- for (int i = 0; i < globalList.Count; i++)
- {
- //body = body + globalList[i].ToString();
- Console.WriteLine(globalList[i].ToString());
- }
- //Console.WriteLine(body);
- 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
- })
- {
- message.IsBodyHtml = true;
- smtp.Send(message);
- Console.WriteLine("email sent");
- }
- return;
- }
- {
- //ping();
- //Console.WriteLine("body");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement