当前位置:网站首页>[recommended by bloggers] C WinForm regularly sends email (with source code)

[recommended by bloggers] C WinForm regularly sends email (with source code)

2022-07-06 10:53:00 xcLeigh

【 Bloggers recommend 】C# Winform Send email regularly ( Source code attached )

C# WinForm+Oracle+Email

1. Support for oracle Data regular query , Then send the query results to the email ;
2. Flexible and configurable , Log directory , Database related connections , The fields shown , The format of the presentation , Email sent , Form style, etc ;
3. On this basis , Support extended , Query data regularly ( Any database ), Send email ( SMS );

Form style

 Insert picture description here

1. Support for minimization , Close hidden taskbar ;
2. The mailbox and database are configured , Start thread , Perform tasks ;
3. Output each processing data log

  • Minimize the form
  •  Insert picture description here

Form code

public ToDataEmail()
{
   InitializeComponent();
   // Default form maximization 
   //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
   SysFinalUtil.appLog = txtSysLog.Text + "log";
   SysFinalUtil.appLog2 = txtSysLog.Text;
   this.txtMess.Text = WriteFileUtil.ReadTxt();
}

#region  Thread start end 

private void btnStart_Click(object sender, EventArgs e)
{
   // SMS receiving thread 
   WriteFileUtil.WriteFileLog("--------------------- Enter the regular query data sending mailbox ", "log");
   EmailData sh = new EmailData();
   EmailData.SysEmailName = txtSysEmailName.Text;
   EmailData.SysEmailPass = txtSysEmailPass.Text;
   EmailData.UserEmailName = txtUserEmailName.Text;
   EmailData.SysEmailTitle = txtSysEmailTitle.Text;
   EmailData.SysExecuteTime = int.Parse(txtSysExecuteTime.Text);

   DBHelper.OracleDBHelper.linkConn = this.txtOracleLjc.Text;

   EmailData.OracleSql = txtOracleSql.Text;
   EmailData.OracleField = txtOracleField.Text;
   EmailData.OracleFieldDetail = txtOracleFieldDetail.Text;

   SysFinalUtil.appLog = txtSysLog.Text+"log";
   SysFinalUtil.appLog2 = txtSysLog.Text;

   string color = "1";
   string style = "1";
   if (rbColor1.Checked) { color = "1"; }
   else if (rbColor2.Checked) { color = "2"; }
   else if (rbColor3.Checked) { color = "3"; }
   if (rbStyle1.Checked) { style = "1"; }
   else if (rbStyle2.Checked) { style = "2"; }

   EmailData.SysColor = color;
   EmailData.SysStyle = style;

   glo2.GlobalValue2.Email_RecvHandle = new Thread(sh.Rev_RunEmail);
   glo2.GlobalValue2.Email_RecvHandle.Start();
   this.btnClose.Enabled = true;
   this.btnStart.Enabled = false;

}

private void btnClose_Click(object sender, EventArgs e)
{
   glo2.GlobalValue2.Email_RecvHandle.Abort();

   this.btnStart.Enabled = true;
   this.btnClose.Enabled = false;
   WriteFileUtil.WriteFileLog("--------------------- Close the data thread ", "log");
}
#endregion

private void ToDataEmail_Load(object sender, EventArgs e)
{
   if (glo2.GlobalValue2.Email_RecvHandle == null)
   {
       this.btnStart.Enabled = true;
       this.btnClose.Enabled = false;
   }
   else
   {
       this.btnClose.Enabled = true;
       this.btnStart.Enabled = false;
   }
}

private void ToDataEmail_FormClosed(object sender, FormClosedEventArgs e)
{
   this.WindowState = FormWindowState.Minimized;
   this.Hide();
   return;
}

private void ToDataEmail_FormClosing(object sender, FormClosingEventArgs e)
{
   this.WindowState = FormWindowState.Minimized;
   this.Hide();
   e.Cancel = true;
   return;
}

private void nfiLow_MouseDoubleClick(object sender, MouseEventArgs e)
{
   this.Show();
   //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
}

private void tsmixcSharp_Click(object sender, EventArgs e)
{
   Process.Start("https://blog.csdn.net/weixin_43151418");
}

private void tsmiShow_Click(object sender, EventArgs e)
{
   this.Show();
   //this.WindowState = System.Windows.Forms.FormWindowState.Maximized;
}

private void tsmiVis_Click(object sender, EventArgs e)
{
   this.Hide();
}

private void tsmiExit_Click(object sender, EventArgs e)
{
   //WriteFileUtil.WriteFileLog("--------------------- Exit procedure ", "log");
   nfiLow.Visible = false;
   System.Environment.Exit(0);// All threads exit 
   this.Close();
   this.Dispose();
   System.Windows.Forms.Application.Exit();
}

private void timer1_Tick(object sender, EventArgs e)
{
   this.txtMess.Text = WriteFileUtil.ReadTxt();
}

private void tsmiTxtLoad_Click(object sender, EventArgs e)
{
   this.txtMess.Text = WriteFileUtil.ReadTxt();
}

private void tsmiTxtClear_Click(object sender, EventArgs e)
{
   if (WriteFileUtil.clearTxt())
   {
       //MessageBox.Show(" Emptying complete !");
       this.txtMess.Text = WriteFileUtil.ReadTxt();
   }
   else
   {
       MessageBox.Show(" Empty exception !");
       this.txtMess.Text = WriteFileUtil.ReadTxt();
   }
}

Run the file

 Insert picture description here
double-click XcSharpApp.exe function

Source code address

【 Bloggers recommend 】C# Winform Send email regularly ( Source code attached )

原网站

版权声明
本文为[xcLeigh]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207060912197884.html