private void tmrExecutor_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
 {
     ServiceLog.WriteErrorLog("sadsfasfasf");
     //Do your Sending email work here
     ServiceLog.WriteErrorLog("doslo");                                                         // Here you can write the
     ServiceLog.SendEmail("*****@*****.**", "Daily Report of DailyMailSchedulerService on " + DateTime.Now.ToString("dd-MMM-yyyy"), "jj");
 }
 protected override void OnStop()
 {
     //timer1.AutoReset = false;
     // timer1.Enabled = false;
     timer1.Stop();
     ServiceLog.WriteErrorLog("Daily Reporting service stopped");
 }
 protected override void OnStart(string[] args)
 {
     // timer1.AutoReset = true;
     //timer1.Enabled = true;
     // timer1.Elapsed += new ElapsedEventHandler(tmrExecutor_Elapsed); // adding Event
     // timer1.Interval = 60000; // Set your time here
     // timer1.Enabled = true;
     timer1.Start();
     ServiceLog.WriteErrorLog("Daily Reporting service started");
 }
 public NotificationService()
 {
     InitializeComponent();
     InitializeComponent();
     ServiceLog.WriteErrorLog("init");                                                         // Here you can write the
     //timer1 = new System.Timers.Timer();
     timer1 = new Timer(1 * 60 * 1000)
     {
         AutoReset = true
     };
     timer1.Elapsed += tmrExecutor_Elapsed;
     return;
 }
        /// <summary>
        /// Send Email with cc bcc with given subject and message.
        /// </summary>
        /// <param name="ToEmail"></param>
        /// <param name="cc"></param>
        /// <param name="bcc"></param>
        /// <param name="Subj"></param>
        /// <param name="Message"></param>
        public static void SendEmail(String ToEmail, String Subj, string Message)
        {
            //Reading sender Email credential from web.config file
            ServiceLog.WriteErrorLog("poslano doslo");
            string      subject          = "service";
            string      body             = "service email.";
            string      FromMail         = "*****@*****.**";
            string      emailFormAdvokat = "*****@*****.**";
            string      emailTo          = emailFormAdvokat;
            MailMessage mail             = new MailMessage();
            SmtpClient  SmtpServer       = new SmtpClient("smtp.gmail.com");

            mail.From = new MailAddress(FromMail);
            mail.To.Add(emailTo);
            mail.Subject    = subject;
            mail.Body       = body;
            SmtpServer.Port = 587;
            SmtpServer.UseDefaultCredentials = false;
            SmtpServer.Credentials           = new System.Net.NetworkCredential("*****@*****.**", "Rstest123456");
            SmtpServer.EnableSsl             = true;
            SmtpServer.Send(mail);
            ServiceLog.WriteErrorLog("poslano");
        }