Hi Friends,
I have one requirement like to send 25 mail every week.So what i did,I took one count and made count++ on sending every mail.When it reached to 25 it displays alert already crossed limit for this week.But my problem is that how to reset that count on start of the week i.e on Monday.
Here some code that i have written.
try
{
string body = "";
string tbl_custInfo = "";
int countno1=1;
int countno=1;
string xmlfile = Server.MapPath("App_code/count.xml").Trim().ToLower();
XmlDocument xmldoc = new XmlDocument();
xmldoc.Load(xmlfile);
XmlNodeList CountNodeList = xmldoc.SelectNodes("//section");
foreach (XmlNode CountNode in CountNodeList)
{
if (CountNode.HasChildNodes)
{
countno =Convert.ToInt32(CountNode.ChildNodes[0].InnerText.Trim().ToLower());
var testDay = DateTime.Now.DayOfWeek.ToString();
if ((testDay == "Monday" || testDay == "Tuesday" || testDay == "Wednesday" || testDay == "Thursday" || testDay == "Friday" || testDay == "Saturday" || testDay == "Sunday") && (countno <= 3))
{
tbl_custInfo = "<table style='border:solid 1px #eee;padding-removed30px;' align='center' width='100%'>";
tbl_custInfo += "<tr><td colspan='2' style='border-removedsolid 1px #aec6d8;text-align:center;font-weight:bold;color:#8d8f8a;'>Customer Contact Details</td></tr>";
tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Name :</td><td style='border-removedsolid 1px #eee;'>" + txtName.Value.Trim() + "</td></tr>";
tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Phone :</td><td style='border-removedsolid 1px #eee;'>" + txtPhone.Value.Trim() + "</td></tr>";
tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Email :</td><td style='border-removedsolid 1px #eee;'>" + txtEmail.Value.Trim() + "</td></tr>";
tbl_custInfo += "<tr><td style='border-removedsolid 1px #eee;'>Message :</td><td style='border-removedsolid 1px #eee;'>" + txtComment.Value.Trim() + "</td></tr>";
tbl_custInfo += "</table><br/><br/>";
body = "<br/>" + tbl_custInfo;
SmtpClient sc = new SmtpClient();
MailMessage mm = new MailMessage();
if (ConfigurationManager.AppSettings["MailFrom"].ToString().Trim() != "")
{
mm.From = new MailAddress(ConfigurationManager.AppSettings["MailFrom"].ToString().Trim(), txtEmail.Value.ToString().Trim());
}
if (ConfigurationManager.AppSettings["MailTo"].ToString().Trim() != "")
{
mm.To.Add(ConfigurationManager.AppSettings["MailTo"].ToString().Trim());
}
if (ConfigurationManager.AppSettings["MailBCc"].ToString().Trim() != "")
{
mm.Bcc.Add(ConfigurationManager.AppSettings["MailBCc"].ToString().Trim());
}
mm.Subject = ConfigurationManager.AppSettings["Subject"].ToString().Trim();
mm.ReplyTo = new MailAddress(txtEmail.Value);
mm.Body = body;
mm.IsBodyHtml = true;
sc.Send(mm);
countno1 = countno1 + 1;
CountNode.ChildNodes[0].InnerText = countno1.ToString();
xmldoc.Save(xmlfile);
this.ClientScript.RegisterStartupScript(this.GetType(), "animo", "<script language=\"javaScript\">" + "alert('Thanks for Contacting Us.');" + "window.location.href='contact.aspx';" + "<" + "/script>");
}
else
{
this.ClientScript.RegisterStartupScript(this.GetType(), "animo", "<script language=\"javaScript\">" + "alert('no more available time slots and to try again in 14 (or 7) days.');" + "window.location.href='contact.aspx';" + "<" + "/script>");
}
}
}
}
catch { }
Please help me out.