C# 需要处理电子邮件应用程序。若要在电子邮件内容正文中获取新行,请执行以下操作:

C# 需要处理电子邮件应用程序。若要在电子邮件内容正文中获取新行,请执行以下操作:,c#,C#,使用Environment.NewLine作为strbreak变量。不要只在此处复制和粘贴代码。告诉我们到底出了什么问题,哪里出了问题,以及你的期望。 namespace email { public partial class Form1 : Form { SqlConnection s = new SqlConnection("Data Source=CHITHU;Initial Catalog=SecurTimeV5.4.0.3;Integrated Sec

使用
Environment.NewLine
作为
strbreak
变量。

不要只在此处复制和粘贴代码。告诉我们到底出了什么问题,哪里出了问题,以及你的期望。
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"); 
            }
        }
    }
}