需要处理电子邮件应用程序.在电子邮件内容的正文中获取新行

本文关键字:电子邮件 正文 获取 新行 处理 应用程序 | 更新日期: 2023-09-27 18:20:12

namespace email
{
    public partial class Form1 : Form
    {
        SqlConnection s = new SqlConnection("Data Source=CHITHU;Initial Catalog=SecurTimeV5.4.0.3;Integrated Security=True");
        String strBody = "";
        String strbreak = "'r'n";
        MailMessage mail = new MailMessage();
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            DateTime now = DateTime.Now;
            int n = (int)now.DayOfWeek;
            Boolean isDataExists = false;
            String strNameList = "";
            {
                s.Open();
                SqlCommand cmd = new SqlCommand("Select * from MASTERPROCESSDAILYDATA where PDate = CONVERT(DATE, GETDATE()) and LateBy != 'NULL'and LateBy>'00:30:00' and Dept_Name ='admin '", s);
                isDataExists = false;
                strNameList = "";
                SqlDataReader dr = cmd.ExecuteReader();
                while (dr.Read())
                {
                    string h = (String)dr["LateBy"];
                    DateTime dt = Convert.ToDateTime(h);
                    DateTime up = dt.Add(new TimeSpan(0, -30, 0));
                    String st = up.ToString("HH:mm");
                    isDataExists = true;
                    strNameList += dr["Emp_ID"] + " " + dr["Emp_Name"] + " " + st + " " + dr["In_Punch"] + strbreak ;
                }
                dr.Close();
                strBody += "Late Comers Report for this half day";
                strBody += strbreak;
                strBody += "-----------------------";
                strBody += strbreak;

                if (isDataExists)
                {
                    strBody += "Employee ID | Employee Name | |lateby|Date| Time ";
                    strBody += strbreak;
                }
                else
                    strBody += "No late comers today"+strbreak;
            }
            SmtpClient smptsrever = new SmtpClient("smtp.gmail.com", 587);
            smptsrever.EnableSsl = true;
            try
            {
                smptsrever.DeliveryMethod = SmtpDeliveryMethod.Network;
                smptsrever.UseDefaultCredentials = false;
                smptsrever.Credentials = new System.Net.NetworkCredential("alnasiyaattendance@gmail.com", "automail");
                mail.To.Add("chithraep1@gmail.com");
                mail.From = new MailAddress("alnasiyaattendance@gmail.com");
                mail.Subject = "Late Comers Report from Office";
                mail.IsBodyHtml = true;
                mail.Body = strBody;
                mail.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure;
                smptsrever.Send(mail);
                MessageBox.Show("Report sent successfully");
            } 
            catch (Exception) 
            { 
                MessageBox.Show("delivery failed"); 
            }
        }
    }
}

需要处理电子邮件应用程序.在电子邮件内容的正文中获取新行

strbreak变量使用Environment.NewLine