Hi,
I have crrated below windows service and installed it using InstallShield. I am able to see the windows service Started in the Control Panel-Services but I am not getting any email when the minutes turns to 30.
Can anyone help please...
I have crrated below windows service and installed it using InstallShield. I am able to see the windows service Started in the Control Panel-Services but I am not getting any email when the minutes turns to 30.
Can anyone help please...
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Diagnostics; using System.Linq; using System.ServiceProcess; using System.Text; using System.Net.Mail; namespace MyTestWindowsService { public partial class MyTestWindowsService : ServiceBase { public MyTestWindowsService() { InitializeComponent(); if (!System.Diagnostics.EventLog.SourceExists("MyTestWindowsService")) { System.Diagnostics.EventLog.CreateEventSource("MySource", "MyNewLog"); } eventLog1.Source = "MyEventLogSource"; eventLog1.Log = "MyNewLog Comes here!"; } protected override void OnStart(string[] args) { eventLog1.WriteEntry("In OnStart"); } protected override void OnStop() { eventLog1.WriteEntry("In onStop."); } protected override void OnContinue() { eventLog1.WriteEntry("In OnContinue."); } private void timer1_Tick(object sender, EventArgs e) { if (DateTime.Now.Minute == 30) { eventLog1.WriteEntry("starting to send email."); try { MailMessage mail = new MailMessage(); SmtpClient SmtpServer = new SmtpClient("smtp.gmail.com"); mail.From = new MailAddress("it@mydomain.com"); mail.To.Add("jassim@mydomain.com"); mail.Subject = "Test Mail"; mail.Body = "This is for testing SMTP mail from GMAIL"; SmtpServer.Port = 587; SmtpServer.Credentials = new System.Net.NetworkCredential("it@mydomain.com", "mypassword"); SmtpServer.EnableSsl = true; SmtpServer.Send(mail); eventLog1.WriteEntry("email sent."); } catch (Exception ex) { // MessageBox.Show(ex.ToString()); eventLog1.WriteEntry("failed sending email."); } } } } }