问题
Hi I need help regarding sending email periodically in Spring mvc,can anyone suggest which is the best way and how i can achieve this,
回答1:
If it has to be from inside the application, you could add a Spring @Scheduled
Service within it, and let this one send out your emails.
Akin to
// once every hour, on top of the hour, Mondays to Fridays
@Scheduled(cron = * 0 * * * MON-FRI)
public void sendMail() {
//mail stuff here
}
回答2:
Run scheduled tasks outside of your application. Use crontab or the like.
回答3:
I would say that you would use a Quartz schedule to handle this. There is some documentation about scheduling tasks here:
http://docs.spring.io/spring/docs/current/spring-framework-reference/html/scheduling.html
回答4:
There is a very good compatibility with Spring 3 + QuartZ Job Scheduler. Using QuartZ you can schedule a cron trigger which can easily send emails periodically and the best thing in this approach is, everything is very easy to implement and configurable. I would suggest you to please go through the below links:
- http://quartz-scheduler.org/
- http://www.mkyong.com/spring/spring-quartz-scheduler-example/
来源:https://stackoverflow.com/questions/25051958/best-way-for-sending-automatic-email-periodically-in-spring-mvc