Get Machine Information And Send Via E-mail Using C#

Here, I am going to explain how to get your system configuration in an email. Using this article, you can get your machine configuration and send it via an email, so if you want to get any machine information, then just run this code on a particular machine and get all the information related to the configuration of the machine. Here, I am running command from the command prompt and an output of command prompt; write to the string. Using systeminfo command, you can get all the configuration related stuff of your machine.

Step to follow

  1. Add the necessary namespace in the file given below.
    1. using System.Collections.Generic;  
    2. using System;  
    3. using System.ComponentModel;  
    4. using System.Data;  
    5. using System.Drawing;  
    6. using System.Linq;  
    7. using System.Net.Mail;  
    8. using System.Text;  
    9. using System.Text.RegularExpressions;  
    10. using System.Threading.Tasks;  
    11. using System.Windows.Forms;  
  1. Run the command to get the information.
    1. System.Diagnostics.Process process = new System.Diagnostics.Process();  
    2. System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo();  
    3. startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;  
    4. startInfo.FileName = "cmd.exe";  
    5. startInfo.Arguments = "/c systeminfo";  
    6. startInfo.RedirectStandardOutput = true;  
    7. startInfo.UseShellExecute = false;  
    8. process.StartInfo = startInfo;  
    9. process.Start();  
  1. Read the output generated by the command and write it to the string.
    1. string output = process.StandardOutput.ReadToEnd(); process.WaitForExit();  
  1. Send out a command via an email.
    1. MailMessage mail = new MailMessage();  
    2. SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com");  
    3. mail.From = new MailAddress("[email protected]");  
    4. mail.To.Add("[email protected]");  
    5. mail.Subject = "System Configurations";  
    6. mail.IsBodyHtml = true;  
    7. mail.Body = output;  
    8. SmtpServer.Port = 465;  
    9. SmtpServer.Credentials = new System.Net.NetworkCredential("[email protected]""password");  
    10. SmtpServer.EnableSsl = true;  
    11. SmtpServer.Send(mail);  
    12. Application.Exit();