开发者

Trigger email on specific date

I have C# web application that I want it to send out an email on a certain date, such as if equipment isn't returned on the day it was due. Data is in MS SQL database.

I've got all the email code already done, and I'm just curious how do I trigger this email, say after the COB on that particular day?

开发者_JS百科

Thanks,

Eric


Create a small console application that runs as a scheduled task.

It would do something like the following:

  1. Check the email database for unsent emails
  2. Check each unsent email for it's send date
  3. if the send date is equal to DateTime.Now then send the email
  4. Mark the email as sent
  5. Repeat foreach email
  6. Application exits an then runs again according to the scheduled task's settings

Updated

You mentioned you would like to do this with a trigger.. well I have never done that before, but have looked into it. I went with the console application approach. I liked this better. But here is a link on what I found on the trigger approach.


You make an application that queries the database for all emails that should be sent out today and sends the emails. You then schedule that application to run each day with task scheduler.


Quartz scheduler is a nice free c# open source option. Follow link: http://quartznet.sourceforge.net/


Without some piece of information changing in the database that you can observe, you're going to end up doing this with a scheduled task, a service, or a db job.

I wouldn't even bother using C# for this since SQL server has the ability to send email. Just setup a job in SQL server that runs every day after close of business that creates a cursor of the unsent mails and sends them using the native ability to do so that's in SQL server.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜