简体   繁体   English

如何使用 java Spring MVC 安排邮件

[英]How can I Schedule mail using java Spring MVC

I have created an application in which I want to add schedule mail feature.我创建了一个应用程序,我想在其中添加计划邮件功能。 I have created application using Java spring MVC.我已经使用 Java spring MVC 创建了应用程序。 Is there a way to schedule mail using Java spring.有没有办法使用 Java spring 来安排邮件。 I want to send mail 24 hours before the event is occured.我想在事件发生前 24 小时发送邮件。

You can create a job with using the @Scheduled annotation.您可以使用@Scheduled注释创建作业。 Every job's tick (for example, every day at 6 AM) you can check which messages are ready to be sent and then send them.每个作业的滴答声(例如,每天早上 6 点)您可以检查哪些消息已准备好发送,然后发送它们。 Don't forget also to add the @EnableScheduling annotation in your config.不要忘记在您的配置中添加@EnableScheduling注释。

@Component
public class MailSenderJob {

   @Scheduled(cron = "0 0 6 * * ?")
   public void execute() {
      ...
      send(messages);
    }
}

For more information about scheduling check the Scheduling Tasks guide.有关调度的更多信息,请查看调度任务指南。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM