Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

send email every 5 minutes c#

public partial class Scheduler : ServiceBase
   {
       System.Timers.Timer createOrderTimer;
       private Timer timer1 = null;
       public Scheduler()
       {
           InitializeComponent();
       }

       protected override void OnStart(string[] args)
       {
           ////timer1 = new Timer();
           ////this.timer1.Interval = 30000;
           ////this.timer1.Elapsed += new System.Timers.ElapsedEventHandler(this.timer1_Tick);
           ////timer1.Enabled = true;
           ////Library.WriteErrorLog("Test Window Service started");
           createOrderTimer = new System.Timers.Timer();
           createOrderTimer.Elapsed += new System.Timers.ElapsedEventHandler(GetMail);
           createOrderTimer.Interval = 180000;
           createOrderTimer.Enabled = true;
           createOrderTimer.AutoReset = true;
           createOrderTimer.Start();
       }

       private void timer1_Tick(object sender, ElapsedEventArgs e)
       {
           Library.WriteErrorLog("Timer Ticked and some job has been done successfully");
       }

       protected override void OnStop()
       {
           timer1.Enabled = false;
           Library.WriteErrorLog("Test Window Service stopped");
       }

       public void GetMail(object sender, System.Timers.ElapsedEventArgs args)
       {
           NetworkCredential cred = new NetworkCredential("abc@gmail.com", "abc");
           MailMessage msg = new MailMessage();
           msg.To.Add("to@abc.com");
           msg.Subject = "Welcome Venkat";

           msg.Body = "You Have Successfully Entered to venkat World!!!";
           msg.From = new MailAddress("from@gmail.com"); // Your Email Id
           SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
          // SmtpClient client1 = new SmtpClient("smtp.mail.yahoo.com", 465);
           client.Credentials = cred;
           client.EnableSsl = true;
           client.Send(msg);
       }
   }
Comment

PREVIOUS NEXT
Code Example
Csharp :: add rotation 
Csharp :: wpf dispatcher timer is inaccurate 
Csharp :: how to get the dynamic year for your web app in mvc 
Csharp :: unity move camera to player fluent 
Csharp :: exit form esc winforms 
Csharp :: jobject alternative in system.text.json 
Csharp :: DataGridView set column cell Combobox 
Csharp :: set time on audio source unity 
Csharp :: jq map over array 
Csharp :: selecteditem treeview wpf 
Csharp :: dynamics 365 create record c# 
Csharp :: blazor conditional reenreing 
Csharp :: c# namespace name form1 could not be found 
Csharp :: unity transparent sprite 
Csharp :: wpf mvvm crud example 
Csharp :: validate preview input number wpf 
Csharp :: C# decimal built-in methods 
Csharp :: get link element revit api 
Csharp :: office open xml check if row is empty 
Csharp :: c# aabb box rotate 
Csharp :: process method in scala 
Csharp :: C# assign integer 
Csharp :: finding holydays asp.net 
Csharp :: Fix Array outside the bonus 
Csharp :: C# if (if-then) Statement 
Csharp :: user control equivalent event for form.shown c# 
Csharp :: C# data base sql 
Csharp :: c# alert message 
Csharp :: unity check if swipe not tap 
Csharp :: when creating a new boolean column in an existing table how to set the default value as true in c# models code first 
ADD CONTENT
Topic
Content
Source link
Name
7+5 =