-1
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("[email protected]", "automail");
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
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");
}
}
}
}
不要只是在這裏複製並粘貼你的代碼。告訴我們到底發生了什麼問題,您遇到問題的位置以及您的期望。 – Rob