Best way for sending automatic email periodically in Spring mvc

倾然丶 夕夏残阳落幕 提交于 2021-02-10 15:00:42

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!