Sending Emails Via Quartz Job
I need to send emails to users a week after they register. What would be the better way:
- Scheduling a Quartz job that runs daily and gets all emails of users registered a week ago.
- Scheduling a Quartz job and a trigger for 1 week after user registration date for each user that signs up.
Regarding the first way, if the job is running and has sent half of the emails on the list and the server shuts down, we will have to add extra logic to make sure we log emails that are sent and recover from where we left off.
The second one seems better because it does not send out all the emails at the same time (causing load on the smtp server), but it also requires a trigger for each user which could take up a lot of database space.
Are my assumpt开发者_如何学运维ions correct? Which way is the better way for recovering through server going down, etc.
Polling to check if there are any eligible users to email is the most robust and simple. I considered creating a Quartz trigger for a similar scenario, but I still required some kind of persistance model.
Have a Quartz job scheduled to check on an interval, and send while there is an eligible user to email.
I implemented a framework based on MvcMailer to do exactly this (later switching to NVelocity). See my post for an overview: https://github.com/smsohan/MvcMailer/pull/12#issuecomment-1368050
精彩评论