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:
- Check the email database for unsent emails
- Check each unsent email for it's send date
if
the send date is equal toDateTime.Now
then send the email- Mark the email as sent
- Repeat
foreach
email - 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.
精彩评论