0

I have an ASP.NET Webform application (C#) configured in an IIS server. The application connects to a database on another server for its normal operation.

Now I need to create an auto emailing system. This system should check certain conditions in the database, and based on that it should send automatic emails to certain email ids. I have an smtp mail server, and I know how to do the automatic emailing using C#.

This emailing should be triggered daily at a certain time. So how will I configure such a job in my server? What are my options?

I am pretty new to the ASP world. Thanks for help.

Erdnase
  • 750
  • 3
  • 12
  • 25
  • You can use a Windows Service or a Console Application in Scheduled Task. – Emanuele May 23 '18 at 07:46
  • 1
    You can use `Quartz.Net `. for more info: https://www.quartz-scheduler.net/ – Hasan Fathi May 23 '18 at 07:49
  • You can create your own scheduler, which there should be more than a few tutorials on. As an alternative you can use scheduling libraries like [FluentScheduler](https://github.com/fluentscheduler/FluentScheduler), [Quartz](http://www.quartz-scheduler.org/) or [Hangfire](https://www.hangfire.io/). All of them should support recurring jobs, that can be scheduled daily, weekly etc. – Cicero May 23 '18 at 07:50
  • Possible duplicate of [Best way to run scheduled tasks](https://stackoverflow.com/questions/542804/best-way-to-run-scheduled-tasks) – CodeNotFound May 23 '18 at 07:53
  • I have used [Hangfire](https://www.hangfire.io/) in the past to send all my emails. – Pieter Alberts May 23 '18 at 07:55

3 Answers3

2

I would use Hangfire and create a recurring job(cron job) to check the db if the mails need to be sent... if so, en queue Hangfire jobs for each mail that needs to be sent. It works extremely well, I have implemented this in the past.

If you decide to go this route, let me know if you need some help.

Pieter Alberts
  • 829
  • 1
  • 7
  • 23
0

If your want to keep the logic and code of your mailing system separated from your other application, you could also generate a separate project (a C#.net console application which generates a .exe file), and launch it at your desired time intervals using Windows Task Scheduler.

Daniël Camps
  • 1,737
  • 1
  • 22
  • 33
0

Try exploring Scheduled Tasks in window server. You can write a console application in c# and then point your schedule task to run the console application at a certain time.

If you really want to use asp.net website then you can write a powershell script to call the asp.net web service and use schedule task to run the script at a certain time.

Chandra Rana
  • 91
  • 1
  • 2