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");
}
}
}
}
答案 0 :(得分:0)
将Environment.NewLine
用于strbreak
变量。