Click here to Skip to main content
15,922,894 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
send email at a scheduled time and date in Asp.net
Posted

 
Share this answer
 
//Global file events start
C#
void Application_Start(object sender, EventArgs e)
    {
        System.Timers.Timer myTimer = new System.Timers.Timer();
        myTimer.Interval =60000; //3600000;
        myTimer.AutoReset = true;
        myTimer.Elapsed += new ElapsedEventHandler(myTimer_Elapsed);
        myTimer.Enabled = true;
    }

    public void myTimer_Elapsed(object source, System.Timers.ElapsedEventArgs e)
    {
        // Object initialization of data link library
        ScheduleMailandSMS _ScheduleMailandSMS = new ScheduleMailandSMS();        
        DataTable dttemppayinslip = GetData_PayinslipSendsmmail();
        foreach (DataRow dr in dttemppayinslip.Rows)
{
        _ScheduleMailandSMS.SendOrderDetailsMail("", "");
    }
}
//Global file events End

//Mail send function Start
public void SendOrderDetailsMail(string bodystr, string AMEmailID)
    {
        DataTable dtemailsetting = _objemailsetting.GetEmailSettingAll();
        if (dtemailsetting.Rows.Count > 0)
        {
            MailMessage mail = new MailMessage();
            SmtpClient SmtpServer = new SmtpClient(dtemailsetting.Rows[0]["SmtpHost"].ToString());

            mail.From = new MailAddress(dtemailsetting.Rows[0]["AdminEmail_registeruser"].ToString());
            mail.To.Add("pramod,joshi@abc.com");
            mail.Subject = "test mail ";
            mail.Body = bodystr;
            SmtpServer.Port = Convert.ToInt16(dtemailsetting.Rows[0]["SMTPPort"]);
            SmtpServer.Credentials = new System.Net.NetworkCredential(dtemailsetting.Rows[0]["SMTPEmail"].ToString(), dtemailsetting.Rows[0]["SMTPPassword"].ToString());
            SmtpServer.EnableSsl = false;
            mail.IsBodyHtml = true;
            SmtpServer.Send(mail);
        }
        else
        {

        }
    }

//Mail send function End
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900