Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can server and java servlet send auto email without user interactions? [duplicate]

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.

like image 213
darkerror Avatar asked Oct 05 '15 09:10

darkerror


1 Answers

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

like image 107
Serge Ballesta Avatar answered Sep 28 '22 15:09

Serge Ballesta