Click here to Skip to main content
15,881,882 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
hi...
i have a website. i think my website can be publishes with email.so, i want code for emails automatically sends daily to all registered users with out using any setup file. and user can choose certain dates or weeks or months. then what user selected dates only that days emails can be forward from my website how can i do this.please help me.....



thank you...
Posted
Updated 30-Aug-16 9:34am

 
Share this answer
 
Comments
NaniCh 9-Jul-12 3:42am    
thank you for your help...
i use this code it can be ask setup file. i didn't need setup file... please tell me how to write code through wcf service for this...
The easiest way to include Quartz.NET in your application is via Nuget. You can do this either by typing Install-Package Quartz at the Package Manager Console prompt or by right clicking on the project in Visual Studio's Solution Explorer and selecting Manage Nuget Packages.


C#
Quartz consists of 3 primary components - a job, a trigger and a scheduler


Creating Job to Perform

C#
using Quartz;
using System;
using System.Net;
using System.Net.Mail;

namespace ScheduledTaskExample.ScheduledTasks
{
    public class EmailJob : IJob
    {
        public void Execute(IJobExecutionContext context)
        {
            using (var message = new MailMessage("user@gmail.com", "user@live.co.uk"))
            {
                message.Subject = "Test";
                message.Body = "Test at " + DateTime.Now;
                using (SmtpClient client = new SmtpClient
                {
                    EnableSsl = true,
                    Host = "smtp.gmail.com",
                    Port = 587,
                    Credentials = new NetworkCredential("user@gmail.com", "password")
                })
                {
                    client.Send(message);
                }
            }
        }
    }
}


Setting Up Scheduler and Trigger

C#
using Quartz;
using Quartz.Impl;
using System;

namespace ScheduledTaskExample.ScheduledTasks
{
    public class JobScheduler
    {
        public static void Start()
        {
            IScheduler scheduler = StdSchedulerFactory.GetDefaultScheduler();
            scheduler.Start();

            IJobDetail job = JobBuilder.Create<EmailJob>().Build();

            ITrigger trigger = TriggerBuilder.Create()
                .WithDailyTimeIntervalSchedule
                  (s =>
                     s.WithIntervalInHours(24)
                    .OnEveryDay()
                    .StartingDailyAt(TimeOfDay.HourAndMinuteOfDay(0, 0))
                  )
                .Build();

            scheduler.ScheduleJob(job, trigger);
        }
    }
}


Hope this Helps!
 
Share this answer
 
 
Share this answer
 
v3
Comments
NaniCh 9-Jul-12 3:38am    
thank you for your help..
when i use this code the email sent only one time.. i want send emails daily automatically to the users..
perilbrain 9-Jul-12 4:45am    
http://msdn.microsoft.com/en-us/magazine/cc163821.aspx
got this one please check....if it is useful

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