How to Implement Reminder mail with help of asp.net with example
Default.aspx=>
<%@ Page Language="C#" AutoEventWireup="true" Async="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send Mail" />
Default.aspx.cs=>
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;// for backgroundworker class
using System.Net;
using System.Net.Mail;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
BackgroundWorker bw;
protected void Page_Load(object sender, EventArgs e)
{
bw = new BackgroundWorker();
bw.DoWork+=new DoWorkEventHandler(bw_DoWork);
bw.WorkerSupportsCancellation = true;
bw.WorkerReportsProgress = false;
}
public void SendMail()
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("abc@gmail.com");
msg.To.Add("asdf@rediffmail.com");
msg.Body = "Testing the automatic mail";
msg.IsBodyHtml = true;
msg.Subject = "Movie Data";
SmtpClient smt = new SmtpClient("smtp.gmail.com");
smt.Port = 587;
smt.Credentials = new NetworkCredential("abc@gmail.com", "password");
smt.EnableSsl = true;
smt.Send(msg);
string script = "<script>alert('Mail Sent Successfully');self.close();</script>";
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "sendMail", script);
}
public void bw_DoWork(object sender, DoWorkEventArgs e)
{
SendMail();
}
protected void Button1_Click(object sender, EventArgs e)
{
DateTime current_time = DateTime.Now;
current_time = current_time.AddSeconds(10);
Thread.Sleep(10000);
if (current_time == DateTime.Now)
{
bw.RunWorkerAsync();
}
}
}
<%@ Page Language="C#" AutoEventWireup="true" Async="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Send Mail" />
Default.aspx.cs=>
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.ComponentModel;// for backgroundworker class
using System.Net;
using System.Net.Mail;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
BackgroundWorker bw;
protected void Page_Load(object sender, EventArgs e)
{
bw = new BackgroundWorker();
bw.DoWork+=new DoWorkEventHandler(bw_DoWork);
bw.WorkerSupportsCancellation = true;
bw.WorkerReportsProgress = false;
}
public void SendMail()
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("abc@gmail.com");
msg.To.Add("asdf@rediffmail.com");
msg.Body = "Testing the automatic mail";
msg.IsBodyHtml = true;
msg.Subject = "Movie Data";
SmtpClient smt = new SmtpClient("smtp.gmail.com");
smt.Port = 587;
smt.Credentials = new NetworkCredential("abc@gmail.com", "password");
smt.EnableSsl = true;
smt.Send(msg);
string script = "<script>alert('Mail Sent Successfully');self.close();</script>";
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "sendMail", script);
}
public void bw_DoWork(object sender, DoWorkEventArgs e)
{
SendMail();
}
protected void Button1_Click(object sender, EventArgs e)
{
DateTime current_time = DateTime.Now;
current_time = current_time.AddSeconds(10);
Thread.Sleep(10000);
if (current_time == DateTime.Now)
{
bw.RunWorkerAsync();
}
}
}
No comments:
Post a Comment