I have to do a Java project that sends automatic e-mail, taking data like name, CNPJ, etc. in the Oracle database every day at 10:00 am. How to create this?
I have to do a Java project that sends automatic e-mail, taking data like name, CNPJ, etc. in the Oracle database every day at 10:00 am. How to create this?
There are many ways to do this, many even.
One that I find quite usual in the marketplace is the Quartz Scheduler , a task scheduler that supports clustering ) and can be run seamlessly with the Spring Framework.
In this case, just create a task that triggers at the desired time using the same standard of the Unix cron
command. Example:
0 0 10 ? * *
The above expression sets the daily execution to 10 AM, exact time, no seconds or minutes.
Using the Spring framework can help with other tasks such as configuring and sending email, connecting to the database, injecting dependencies, etc.
For more details on setting up Quartz with Spring, see documentation . See also tutorials and examples here / a> and here .
Depending on the volume of emails, you can also integrate Spring Batch to send emails at certain intervals. So, in this scenario, the Quartz task would trigger the Spring Batch task to send e-mail.
You will need several separate things, first of them and a crontab running every day at 10:00 AM, second and a SMTP server configured correctly, only after that should create a class of access to the bank and trigger e- mail address.