public class MailBuilder
extends java.lang.Object
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
mailBuilderFactory denotes the MailBuilderFactory for
creating the mail builderemailDatasink denotes the EmailDatasink used for sending
the emailcurrentUser denotes the current User as the e-mail
recipientfiles denotes the list of attachments to addMailService| Constructor and Description |
|---|
MailBuilder(<any> mailServiceProvider,
<any> tempFileServiceProvider,
<any> zipServiceProvider,
<any> mimeUtilsProvider,
java.lang.String subject,
java.lang.String body,
java.util.List<User> recipients,
InternetAddress from) |
| Modifier and Type | Method and Description |
|---|---|
SimpleMail |
build()
Builds the email using the previously specified options.
|
MailBuilder |
withAttachments(java.util.List<SimpleAttachment> attachments)
Adds a list of attachments.
|
MailBuilder |
withEmailDatasink(EmailDatasink emailDatasink)
Specifies that the given
EmailDatasink should be used instead of the
default (internal) email settings. |
MailBuilder |
withFileAttachments(java.util.List<java.nio.file.Path> attachments)
Adds a list of files as email attachments.
|
MailBuilder |
withTemplateReplacements(java.util.Map<java.lang.String,java.lang.Object> replacements)
Specifies that the email contains a template and specifies which replacements
should be used for template substitution.
|
MailBuilder |
withZippedAttachments(java.lang.String zipFilename)
Specifies that the attachments should be zipped using the provided filename.
|
public MailBuilder(<any> mailServiceProvider,
<any> tempFileServiceProvider,
<any> zipServiceProvider,
<any> mimeUtilsProvider,
java.lang.String subject,
java.lang.String body,
java.util.List<User> recipients,
InternetAddress from)
public MailBuilder withTemplateReplacements(java.util.Map<java.lang.String,java.lang.Object> replacements)
replacements - the replacements for template substitutionMailBuilderpublic MailBuilder withFileAttachments(java.util.List<java.nio.file.Path> attachments)
attachments - the list of files to add as email attachments.MailBuilderpublic MailBuilder withAttachments(java.util.List<SimpleAttachment> attachments)
Paths.attachments - the attachments as byte arrays or PathsMailBuilderpublic MailBuilder withZippedAttachments(java.lang.String zipFilename)
zipFilename - the zip filename.MailBuilderpublic MailBuilder withEmailDatasink(EmailDatasink emailDatasink)
EmailDatasink should be used instead of the
default (internal) email settings.emailDatasink - the EmailDatasink to use.MailBuilderpublic SimpleMail build() throws java.io.IOException, MessagingException
java.io.IOException - if an I/O error occursMessagingException - if sender can not be set