I've been searching all over google and stackoverflow about whether can the server send auto email , for example every monday, using servlet without any user interactions. AT the moment, user has to log in and codes gets excuted. What I want is the server to excute the code at specific time and user don't have to log in and don't even see that. I don't want to relay on users, I want to relay on server instead.
You need to have a non interactive thread in your server. Ideally, this thread should be started by a ServletContextListener
, to be sure that it will be active even before first client connection.
You can either build something from scratch or use a dedicated tool such as the excellent Quartz scheduler, that will do the boiler plate code for you.
Once you have the scheduler, you just need to be able to send mail to a mail server via SMTP. Here again, you can implement the protocol by hand (SMTP is not that hard), but if you do not want to re-invent an oval wheel where round ones are already around, use the javamail API from the Java EE SDK, or another third party library such as the one provided by Apache
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With