Class MailBuilder
java.lang.Object
net.datenwerke.rs.core.service.mail.MailBuilder
Builder class for constructing an email step-by-step by providing the
necessary elements using the builder pattern. By default, the email is sent
using the ReportServer internal email settings. If you need to send the email
to a given
EmailDatasink, you can use
withEmailDatasink(EmailDatasink). A typical email can be constructed
and sent as shown below.
{
@code
SimpleMail mail = mailBuilderFactory.create("my subject text", "my body text", Arrays.asList(currentUser))
.withEmailDatasink(emailDatasink).withFileAttachments(files).withZippedAttachments("myAttachments.zip")
.build();
mailService.sendMail(mail);
}
where
mailBuilderFactorydenotes theMailBuilderFactoryfor creating the mail builderemailDatasinkdenotes theEmailDatasinkused for sending the emailcurrentUserdenotes the currentUseras the e-mail recipientfilesdenotes the list of attachments to add- Finally, the e-mail is sent using the
MailService
-
Constructor Summary
ConstructorsConstructorDescriptionMailBuilder(<any> mailServiceProvider, <any> tempFileServiceProvider, <any> zipServiceProvider, <any> mimeUtilsProvider, String subject, String body, List<User> recipients, InternetAddress from) -
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds the email using the previously specified options.withAttachments(List<SimpleAttachment> attachments) Adds a list of attachments.withEmailDatasink(EmailDatasink emailDatasink) Specifies that the givenEmailDatasinkshould be used instead of the default (internal) email settings.withFileAttachments(List<Path> attachments) Adds a list of files as email attachments.withTemplateReplacements(Map<String, Object> replacements) Specifies that the email contains a template and specifies which replacements should be used for template substitution.withZippedAttachments(String zipFilename) Specifies that the attachments should be zipped using the provided filename.
-
Constructor Details
-
MailBuilder
-
-
Method Details
-
withTemplateReplacements
Specifies that the email contains a template and specifies which replacements should be used for template substitution.- Parameters:
replacements- the replacements for template substitution- Returns:
- the current state of
MailBuilder
-
withFileAttachments
Adds a list of files as email attachments.- Parameters:
attachments- the list of files to add as email attachments.- Returns:
- the current state of
MailBuilder
-
withAttachments
Adds a list of attachments. These can contain byte arrays orPaths.- Parameters:
attachments- the attachments as byte arrays orPaths- Returns:
- the current state of
MailBuilder
-
withZippedAttachments
Specifies that the attachments should be zipped using the provided filename.- Parameters:
zipFilename- the zip filename.- Returns:
- the current state of
MailBuilder
-
withEmailDatasink
Specifies that the givenEmailDatasinkshould be used instead of the default (internal) email settings.- Parameters:
emailDatasink- theEmailDatasinkto use.- Returns:
- the current state of
MailBuilder
-
build
Builds the email using the previously specified options.- Returns:
- the constructed email.
-