Hi,
Hope you are doing great.Yesterday my customer asked me to do automatic email notification for all the members in the project so that Email has to be send on the day when their Membership Expiry date is expired.For that I have written the follwoing piece of code(Query).But today he said me that Email has to be send before 30 days of expiry date.Please help me in this regard.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
namespace soonthyehang
{
public partial class SendAutoEmail : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
SendAutoEmailExp();
}
}
private void SendAutoEmailExp()
{
string time = DateTime.Now.ToString("MM-dd-yyyy");
DataSet ds = new DataSet();
DBUtil.DbUtilResult resTitle = DBUtil.ExecuteQuery("select * from tbl_Member where MembershipExpDate ='" + time + "'");
ds = resTitle.Contents;
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
string EmailAdd, Name, Subject, EmailMsg;
Name = ds.Tables[0].Rows[0]["Name"].ToString();
EmailAdd = ds.Tables[0].Rows[0]["Email"].ToString();
Subject = "Mail from SonnThyehang";
EmailMsg = "Dear" + Name + "Your Soonthyehang Membership Expiry will be expired today";
bool email = EmailHelper.Instance.SendEmail(EmailAdd, Subject, EmailMsg);
if (email)
{
//Code By Ali to Insert values in Email and EmailDeatails Tables
//string CurrentUser = Session["Admin"].ToString();
ArrayList objr = new ArrayList();
objr.Add(Subject);
objr.Add(EmailMsg);
objr.Add(null);
objr.Add(EmailAdd);
DBUtil.DbUtilResult dbResult = DBUtil.Execute("SpInsertEmail", objr);
CustomMessage.ShowMessage("Email Sent Successfully!");
}
else
CustomMessage.ShowMessage("Error in Sending Mail");
}
}
}
}
}