Friday, October 11, 2013

Task Scheduling using GLOBAL File

Task Scheduling using GLOBAL File

 


<%@ Application Language="C#" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Timers" %>
<%@ Import Namespace="System.Net.Mail" %>




<script runat="server">
    void Application_Start(object sender, EventArgs e)
    {
        System.Timers.Timer t = new System.Timers.Timer(30000);
        t.Elapsed += new ElapsedEventHandler(t_Elapsed);
        t.AutoReset = true;
        t.Enabled = true;
    }
    private void t_Elapsed(object sender, ElapsedEventArgs e)
    {
        SmtpClient smtpClient = new SmtpClient();
        System.Net.NetworkCredential basicCredential =
            new System.Net.NetworkCredential("a@a.com", "a");
        MailMessage message = new MailMessage();
        MailAddress fromAddress = new MailAddress("a@a.com");

        smtpClient.Host = "smtp.a.com";
        smtpClient.UseDefaultCredentials = false;
        smtpClient.Credentials = basicCredential;

        message.From = fromAddress;
        message.Subject = "your subject";
        //Set IsBodyHtml to true means you can send HTML email.
        message.IsBodyHtml = true;
        message.Body = "<h1>your message body</h1>";
        message.To.Add("a@a.com");

        try
        {
            smtpClient.Send(message);
        }
        catch (Exception ex)
        {
            //Error, could not send the message
            Response.Write(ex.Message);
        }

    }   



    void Application_End(object sender, EventArgs e)
    {
       



    }
       

    void Application_Error(object sender, EventArgs e)
    {
       



    }


    void Session_Start(object sender, EventArgs e)
    {
       



    }


    void Session_End(object sender, EventArgs e)
    {
       



    }
      

</script>


No comments:

Post a Comment