A reusable mailer service to send emails.
Add the mailer service to the classpath by adding the following maven dependency. Versions haven be found here
<dependency>
<groupId>it.aboutbits.springboot</groupId>
<artifactId>emailservice</artifactId>
<version>x.x.x</version>
</dependency>
If you want to use attachments, you will have to create a bean implementing this interface: AttachmentDataSource.java
This step is optional.
Use the ManageEmail
service to schedule an email.
// @formatter:off
public void sendMail(final String to,final String subject,final String htmlBody,final String plainTextBody) {
manageEmail.schedule(
EmailParameter.builder()
.scheduleAt(OffsetDateTime.now())
.email(EmailParameter.Email.builder()
.fromName(fromName)
.fromAddress(fromAddress)
.recipient(to)
.subject(subject)
.textBody(plainTextBody)
.htmlBody(htmlBody)
.build())
.build()
);
}
// @formatter:on
To read email datasets from the database use this class: QueryEmail.java
If you want to receive a report after each run of the scheduler, create a Bean implementing EmailSchedulerCallback.java
To enable this service just add @EnableEmailService
to your main class. You must also enable @EnableScheduling
to allow the email queue to be processed.
@SpringBootApplication
@EnableEmailService
@EnableScheduling
public class App {
public static void main(final String[] args) {
SpringApplication.run(App.class, args);
}
}
The following configuration options are available:
Name | Default | Description |
---|---|---|
lib.emailservice.migrations.enabled |
true | Enables database migrations. |
lib.emailservice.scheduling.enabled |
true | Enables the scheduler sending the emails. |
lib.emailservice.scheduling.interval |
30000 | Specifies the milliseconds delay between runs of the scheduler. |
To use this library as a local development dependency, you can simply refer to the version BUILD-SNAPSHOT
.
Check out this repository and run the maven goal install
. This will build and install this library as version BUILD-SNAPSHOT
into your local maven cache.
Note that you may have to tell your IDE to reload your main maven project each time you build the library.
To create a new version of this package and push it to the maven registry, you will have to use the GitHub actions workflow and manually trigger it.
About Bits is a company based in South Tyrol, Italy. You can find more information about us on our website.
For support, please contact [email protected].
The MIT License (MIT). Please see the license file for more information.