Send operating system (OS) information on email using C# in ASP.Net

sadiamunirahmed92
 
on Oct 08, 2021 02:28 AM
476 Views

i want to send os information detail on my email address but my code just show detail on execution and issue is that how can send this detail on my email address

<asp:Button ID="btnSend" Text="Send Mail" runat="server" OnClick="btnSend_Click" /> 

 

protected void Page_Load(object sender, EventArgs e)
{
    //os information
    SelectQuery Sq = new SelectQuery("Win32_OperatingSystem");
    ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);
    ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
    foreach (ManagementObject mo in osDetailsCollection)
    {
        Response.Write("Name : " + mo["name"].ToString() + "<br/>");
        Response.Write("Version : " + mo["version"].ToString() + "<br/>");
        Response.Write("Csname : " + mo["csname"].ToString() + "<br/>");
        Response.Write("Boot Device : " + mo["BootDevice"].ToString() + "<br/>");
        Response.Write("Build Number : " + mo["BuildNumber"].ToString() + "<br/>");
        Response.Write("BuildType : " + mo["BuildType"].ToString() + "<br/>");
        Response.Write("Caption : " + mo["Caption"].ToString() + "<br/>");
        Response.Write("CodeSet : " + mo["CodeSet"].ToString() + "<br/>");
        Response.Write("CountryCode : " + mo["CountryCode"].ToString() + "<br/>");
        Response.Write("CreationClassName : " + mo["CreationClassName"].ToString() + "<br/>");
        Response.Write("CSCreationClassName : " + mo["CSCreationClassName"].ToString() + "<br/>");
        //Response.Write("CSDVersion : " + mo["CSDVersion"].ToString() + "<br/>");
        Response.Write("CurrentTimeZone : " + mo["CurrentTimeZone"].ToString() + "<br/>");
        Response.Write("DataExecutionPrevention_Available : " + mo["DataExecutionPrevention_Available"].ToString() + "<br/>");
        Response.Write("DataExecutionPrevention_32BitApplications : " + mo["DataExecutionPrevention_32BitApplications"].ToString() +
        "<br/>");
        Response.Write("DataExecutionPrevention_Drivers : " + mo["DataExecutionPrevention_Drivers"].ToString() + "<br/>");
        Response.Write("DataExecutionPrevention_SupportPolicy : " + mo["DataExecutionPrevention_SupportPolicy"].ToString() + "<br/>");
        Response.Write("Debug : " + mo["Debug"].ToString() + "<br/>");
        Response.Write("Description : " + mo["Description"].ToString() + "<br/>");
        Response.Write("Distributed : " + mo["Distributed"].ToString() + "<br/>");
        Response.Write("EncryptionLevel : " + mo["EncryptionLevel"].ToString() + "<br/>");
        Response.Write("ForegroundApplicationBoost : " + mo["ForegroundApplicationBoost"].ToString() + "<br/>");
        Response.Write("FreePhysicalMemory : " + mo["FreePhysicalMemory"].ToString() + "<br/>");
        Response.Write("FreeSpaceInPagingFiles : " + mo["FreeSpaceInPagingFiles"].ToString() + "<br/>");
        Response.Write("FreeVirtualMemory : " + mo["FreeVirtualMemory"].ToString() + "<br/>");
        Response.Write("InstallDate : " + mo["InstallDate"].ToString() + "<br/>");
        Response.Write("LastBootUpTime : " + mo["LastBootUpTime"].ToString() + "<br/>");
        Response.Write("LocalDateTime : " + mo["LocalDateTime"].ToString() + "<br/>");
        Response.Write("Locale : " + mo["Locale"].ToString() + "<br/>");
        Response.Write("Manufacturer : " + mo["Manufacturer"].ToString() + "<br/>");
        Response.Write("MaxNumberOfProcesses : " + mo["MaxNumberOfProcesses"].ToString() + "<br/>");
        Response.Write("MaxProcessMemorySize : " + mo["MaxProcessMemorySize"].ToString() + "<br/>");
        Response.Write("NumberOfProcesses : " + mo["NumberOfProcesses"].ToString() + "<br/>");
        Response.Write("NumberOfUsers : " + mo["NumberOfUsers"].ToString() + "<br/>");
        Response.Write("OperatingSystemSKU : " + mo["OperatingSystemSKU"].ToString() + "<br/>");
        Response.Write("Organization : " + mo["Organization"].ToString() + "<br/>");
        Response.Write("OSArchitecture : " + mo["OSArchitecture"].ToString() + "<br/>");
        Response.Write("OSLanguage : " + mo["OSLanguage"].ToString() + "<br/>");
        Response.Write("OSType : " + mo["OSType"].ToString() + "<br/>");
        //Response.Write("PAEEnabled : " + mo["PAEEnabled"].ToString() + "<br/>");
        Response.Write("Primary : " + mo["Primary"].ToString() + "<br/>");
        Response.Write("ProductType : " + mo["ProductType"].ToString() + "<br/>");
        Response.Write("RegisteredUser : " + mo["RegisteredUser"].ToString() + "<br/>");
        Response.Write("SerialNumber : " + mo["SerialNumber"].ToString() + "<br/>");
        Response.Write("ServicePackMajorVersion : " + mo["ServicePackMajorVersion"].ToString() + "<br/>");
        Response.Write("ServicePackMinorVersion : " + mo["ServicePackMinorVersion"].ToString() + "<br/>");
        Response.Write("SizeStoredInPagingFiles : " + mo["SizeStoredInPagingFiles"].ToString() + "<br/>");
        Response.Write("Status : " + mo["Status"].ToString() + "<br/>");
        Response.Write("SuiteMask : " + mo["SuiteMask"].ToString() + "<br/>");
        Response.Write("SystemDevice : " + mo["SystemDevice"].ToString() + "<br/>");
        Response.Write("SystemDirectory : " + mo["SystemDirectory"].ToString() + "<br/>");
        Response.Write("SystemDrive : " + mo["SystemDrive"].ToString() + "<br/>");
        Response.Write("TotalVirtualMemorySize : " + mo["TotalVirtualMemorySize"].ToString() + "<br/>");
        Response.Write("TotalVisibleMemorySize : " + mo["TotalVisibleMemorySize"].ToString() + "<br/>");
        Response.Write("Version : " + mo["Version"].ToString() + "<br/>");
        Response.Write("WindowsDirectory : " + mo["WindowsDirectory"].ToString() + "<br/>");
    }
}
 
protected void btnSend_Click(object sender, EventArgs e)
{
    SendHTMLMail();
}
 
public void SendHTMLMail()
{
    StreamReader reader = new StreamReader(Server.MapPath("~/Default.aspx"));
    string readFile = reader.ReadToEnd();
    //Session["Value"] = "welcome";
    //Response.Redirect("~/html.aspx");
 
    string myString = "";
    myString = readFile;
    myString = myString.Replace("$$Name$$", "M.MunirAhmed");
    myString = myString.Replace("$$Class$$", "MSCS ");
    myString = myString.Replace("$$CourseCode$$", "EH-101");
    myString = myString.Replace("$$ProjectName$$", "Ethical Hacking Project");
 
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress("email@gmail.com");
    mail.To.Add(new MailAddress("email@gmail.com"));
    mail.Subject = "Send Mail with HTML File";
    mail.Body = myString.ToString();
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential("email@gmail.com", "pswd");
    smtp.EnableSsl = true;
 
    smtp.Send(mail);
    //lblmsg.Text = "Mail Send .......";
    reader.Dispose();
}

 

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
on Oct 08, 2021 04:24 AM

Refer below code.

HTML

<asp:Button ID="btnSend" Text="Send Mail" runat="server" OnClick="btnSend_Click" />

Namespaces

using System.Management;
using System.Net.Mail;
using System.Text;

Code

protected void Page_Load(object sender, EventArgs e)
{
    Response.Write(GetOSInfo());
}

private string GetOSInfo()
{
    SelectQuery Sq = new SelectQuery("Win32_OperatingSystem");
    ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);
    ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
    StringBuilder sb = new StringBuilder();
    foreach (ManagementObject mo in osDetailsCollection)
    {
        sb.Append("Name : " + mo["name"].ToString() + "<br/>");
        sb.Append("Version : " + mo["version"].ToString() + "<br/>");
        sb.Append("Csname : " + mo["csname"].ToString() + "<br/>");
        sb.Append("Boot Device : " + mo["BootDevice"].ToString() + "<br/>");
        sb.Append("Build Number : " + mo["BuildNumber"].ToString() + "<br/>");
        sb.Append("BuildType : " + mo["BuildType"].ToString() + "<br/>");
        sb.Append("Caption : " + mo["Caption"].ToString() + "<br/>");
        sb.Append("CodeSet : " + mo["CodeSet"].ToString() + "<br/>");
        sb.Append("CountryCode : " + mo["CountryCode"].ToString() + "<br/>");
        sb.Append("CreationClassName : " + mo["CreationClassName"].ToString() + "<br/>");
        sb.Append("CSCreationClassName : " + mo["CSCreationClassName"].ToString() + "<br/>");
        sb.Append("CurrentTimeZone : " + mo["CurrentTimeZone"].ToString() + "<br/>");
        sb.Append("DataExecutionPrevention_Available : " + mo["DataExecutionPrevention_Available"].ToString() + "<br/>");
        sb.Append("DataExecutionPrevention_32BitApplications : " + mo["DataExecutionPrevention_32BitApplications"].ToString() + "<br/>");
        sb.Append("DataExecutionPrevention_Drivers : " + mo["DataExecutionPrevention_Drivers"].ToString() + "<br/>");
        sb.Append("DataExecutionPrevention_SupportPolicy : " + mo["DataExecutionPrevention_SupportPolicy"].ToString() + "<br/>");
        sb.Append("Debug : " + mo["Debug"].ToString() + "<br/>");
        sb.Append("Description : " + mo["Description"].ToString() + "<br/>");
        sb.Append("Distributed : " + mo["Distributed"].ToString() + "<br/>");
        sb.Append("EncryptionLevel : " + mo["EncryptionLevel"].ToString() + "<br/>");
        sb.Append("ForegroundApplicationBoost : " + mo["ForegroundApplicationBoost"].ToString() + "<br/>");
        sb.Append("FreePhysicalMemory : " + mo["FreePhysicalMemory"].ToString() + "<br/>");
        sb.Append("FreeSpaceInPagingFiles : " + mo["FreeSpaceInPagingFiles"].ToString() + "<br/>");
        sb.Append("FreeVirtualMemory : " + mo["FreeVirtualMemory"].ToString() + "<br/>");
        sb.Append("InstallDate : " + mo["InstallDate"].ToString() + "<br/>");
        sb.Append("LastBootUpTime : " + mo["LastBootUpTime"].ToString() + "<br/>");
        sb.Append("LocalDateTime : " + mo["LocalDateTime"].ToString() + "<br/>");
        sb.Append("Locale : " + mo["Locale"].ToString() + "<br/>");
        sb.Append("Manufacturer : " + mo["Manufacturer"].ToString() + "<br/>");
        sb.Append("MaxNumberOfProcesses : " + mo["MaxNumberOfProcesses"].ToString() + "<br/>");
        sb.Append("MaxProcessMemorySize : " + mo["MaxProcessMemorySize"].ToString() + "<br/>");
        sb.Append("NumberOfProcesses : " + mo["NumberOfProcesses"].ToString() + "<br/>");
        sb.Append("NumberOfUsers : " + mo["NumberOfUsers"].ToString() + "<br/>");
        sb.Append("OperatingSystemSKU : " + mo["OperatingSystemSKU"].ToString() + "<br/>");
        sb.Append("Organization : " + mo["Organization"].ToString() + "<br/>");
        sb.Append("OSArchitecture : " + mo["OSArchitecture"].ToString() + "<br/>");
        sb.Append("OSLanguage : " + mo["OSLanguage"].ToString() + "<br/>");
        sb.Append("OSType : " + mo["OSType"].ToString() + "<br/>");
        sb.Append("Primary : " + mo["Primary"].ToString() + "<br/>");
        sb.Append("ProductType : " + mo["ProductType"].ToString() + "<br/>");
        sb.Append("RegisteredUser : " + mo["RegisteredUser"].ToString() + "<br/>");
        sb.Append("SerialNumber : " + mo["SerialNumber"].ToString() + "<br/>");
        sb.Append("ServicePackMajorVersion : " + mo["ServicePackMajorVersion"].ToString() + "<br/>");
        sb.Append("ServicePackMinorVersion : " + mo["ServicePackMinorVersion"].ToString() + "<br/>");
        sb.Append("SizeStoredInPagingFiles : " + mo["SizeStoredInPagingFiles"].ToString() + "<br/>");
        sb.Append("Status : " + mo["Status"].ToString() + "<br/>");
        sb.Append("SuiteMask : " + mo["SuiteMask"].ToString() + "<br/>");
        sb.Append("SystemDevice : " + mo["SystemDevice"].ToString() + "<br/>");
        sb.Append("SystemDirectory : " + mo["SystemDirectory"].ToString() + "<br/>");
        sb.Append("SystemDrive : " + mo["SystemDrive"].ToString() + "<br/>");
        sb.Append("TotalVirtualMemorySize : " + mo["TotalVirtualMemorySize"].ToString() + "<br/>");
        sb.Append("TotalVisibleMemorySize : " + mo["TotalVisibleMemorySize"].ToString() + "<br/>");
        sb.Append("Version : " + mo["Version"].ToString() + "<br/>");
        sb.Append("WindowsDirectory : " + mo["WindowsDirectory"].ToString() + "<br/>");
    }

    return sb.ToString();
}

protected void btnSend_Click(object sender, EventArgs e)
{
    SendHTMLMail(GetOSInfo());
}

public void SendHTMLMail(string body)
{
    MailMessage mail = new MailMessage();
    mail.From = new MailAddress("email@gmail.com");
    mail.To.Add(new MailAddress("email@gmail.com"));
    mail.Subject = "Send Mail with HTML File";
    mail.Body = body;
    mail.IsBodyHtml = true;
    SmtpClient smtp = new SmtpClient();
    smtp.Host = "smtp.gmail.com";
    smtp.Port = 587;
    smtp.UseDefaultCredentials = false;
    smtp.Credentials = new System.Net.NetworkCredential("email@gmail.com", "pswd");
    smtp.EnableSsl = true;
    smtp.Send(mail);
}