Java mail how to send automatically an email on condition

前端 未结 1 793
北海茫月
北海茫月 2021-01-13 16:35

Never used Java mail before.

In my JSF web app, I have an entity (followUp) with a property private Date checkDate; that corresponds to an

相关标签:
1条回答
  • 2021-01-13 17:09

    Based on your question history I know that you're using Glassfish 3 (Java EE 6 with EJB 3.1), so I'd suggest to create a @Singleton EJB with @Schedule method which executes in the background at specified intervals, for example daily at midnight (00:00:00).

    @Singleton
    public class MailReminder {
    
        @Schedule(hour="0", minute="0", second="0", persistent=false)
        public void run() {
            // Do your check and mail job here.
        }
    
    }
    

    That's it. No further configuration is necessary. For testing purposes you could use

        @Schedule(hour="*", minute="*/1", second="0", persistent=false)
    

    to let it run every minute.

    See also:

    • Java EE 6 tutorial - Using timer service
    0 讨论(0)
提交回复
热议问题