将int = 1(多个)添加到email.body

时间:2018-12-10 06:47:07

标签: email process report state-machine

摘要:

  1. 使用Ping(联机/脱机)检查服务器
  2. 检查服务器中的进程(活动/非活动)
  3. 通过电子邮件报告问题。
  

==========身体========

     

192.168.0.1:有效

     

192.168.0.16:无效

     

Chrome浏览器:应用程序正在运行

     

Excel:应用程序正在运行

我添加了变量。

private int net_prob;
private int srv_prob;

我创建了方法。

private void net_chk()
    {
        Ping avengers = new Ping();
        PingReply imdb = avengers.Send("www.google.com", 1000);

        if (imdb.Status == IPStatus.Success)
        {
            label1.Text = "Net is Active...";
            label1.ForeColor = Color.Green;
            net_prob = 0;
        }

        else
        {
            label1.Text = "Net is Deactive...!!!";
            label1.ForeColor = Color.Red;
            internetsorunu = 1;
        }
    }

...和...

private void srv_chk()
    {
        ConnectionOptions conn = new ConnectionOptions() { Username = "\\Administrator", Password = "1234", Authority = "NTLMDOMAIN:" };

        ManagementScope MS = new ManagementScope("\\\\"+ipaddress+"\\root\\CIMV2", conn);
        MS.Connect();

        ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process Where Caption='" + srv_1 + "'");
        ManagementObjectSearcher MOS = new ManagementObjectSearcher(MS, query);

        foreach (ManagementObject queryObj in MOS.Get())
        {
            string sonuc = queryObj["Caption"].ToString();

            if (sonuc == srv_1)
            {
                label2.Text = "Cool...";
                label2.ForeColor = Color.Green;

                srv_prob= 0;
            }
            else
            {
                label2.Text = "What.!";
                label2.ForeColor = Color.Red;

                srv_prob = 1;
            }
        }
    }

...现在... 如何在email.body中将int值(例如:srv_prob等)发送给1?

public bool SendEmail(string konu, string icerik)
        {
            MailMessage ePosta = new MailMessage() { From = new MailAddress("faris@faris.com") };

            ePosta.To.Add("faris@faris.com");

            ePosta.Subject = konu;
            ePosta.Body = icerik;

            SmtpClient smtp = new SmtpClient() { /**/Credentials = new NetworkCredential("info@faris.com", "123456789"), Port = 587, Host = "smtp.faris.com", EnableSsl = true };
            object userState = ePosta;
            bool kontrol = true;
            try
            {
                smtp.SendAsync(ePosta, (object)ePosta);
            }
            catch (SmtpException ex)
            {
                kontrol = false;
                MessageBox.Show(ex.Message, "Error");
            }
            return kontrol;
        }

0 个答案:

没有答案