Package org.ametys.core.util.mail
Class SendMailHelper.MailBuilder
java.lang.Object
org.ametys.core.util.mail.SendMailHelper.MailBuilder
- Enclosing class:
- SendMailHelper
Implements the builder pattern for creating and sending emails.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
sendMail()
Actually send mail.withAsync
(boolean async) If the mail should be sent asynchronously or not.withAttachments
(Collection<File> attachments) Set the optional attachments.withAttachmentsAsStream
(Collection<SendMailHelper.NamedStream> attachments) Set the optional attachments.Set the blind carbon copy address list.Set the carbon copy address list.withDeliveryReceipt
(boolean deliveryReceipt) Set to true to get a delivery receiptwithEmbeddedBase64Resources
(boolean embedBase64Resources) Set to true to embed base64 resources as attachment.withErrorReport
(List<String> errorReport) Set a list to get the send error report.Set the SMTP host.withHTMLBody
(String htmlBody) Set the optional HTML body.Set the optional HTML body.withInlineCSS
(boolean inlineCSS) Set to true to inline CSS rules.withPassword
(String password) Set the SMTP password.withPort
(long port) Set the SMTP port.withReadReceipt
(boolean readReceipt) Set to true to get a read receiptwithRecipient
(String recipient) Set the mail recipientwithRecipients
(List<String> recipients) Set the mail recipientswithSecurityProtocol
(String securityProtocol) Set the security protocol ("starttls", "tlsssl").withSender
(String sender) Set the mail sender.withSingleEmail
(boolean singleEmail) Set to true if a single email with all recipients should be sent.withSubject
(String subject) Set the mail subject.withTextBody
(String textBody) Set the optional text body.Set the SMTP user.
-
Method Details
-
withAsync
If the mail should be sent asynchronously or not.- Parameters:
async
- the asynchronous flag- Returns:
- this builder
-
withSubject
Set the mail subject. This parameter is mandatory.- Parameters:
subject
- the mail subject- Returns:
- this builder
-
withHTMLBody
Set the optional HTML body. May be null.- Parameters:
htmlBody
- the HTML mail body- Returns:
- this builder
-
withHTMLBody
public SendMailHelper.MailBuilder withHTMLBody(String htmlBody, Map<String, Pair<String, String>> embeddedResource) Set the optional HTML body. May be null.- Parameters:
htmlBody
- the HTML mail bodyembeddedResource
- a map representing the resource related to the htmlBody. can be null. the map map is composed of the resource URI identified by the content ID used in the html body- Returns:
- this builder
-
withTextBody
Set the optional text body. May be null.- Parameters:
textBody
- the text mail body- Returns:
- this builder
-
withAttachments
Set the optional attachments. May be null.- Parameters:
attachments
- the file attachments- Returns:
- this builder
-
withAttachmentsAsStream
public SendMailHelper.MailBuilder withAttachmentsAsStream(Collection<SendMailHelper.NamedStream> attachments) Set the optional attachments. May be null.- Parameters:
attachments
- the input stream attachments- Returns:
- this builder
-
withRecipient
Set the mail recipient- Parameters:
recipient
- the recipient address- Returns:
- this builder
-
withRecipients
Set the mail recipients- Parameters:
recipients
- the recipients addresses- Returns:
- this builder
-
withSender
Set the mail sender.- Parameters:
sender
- the mail sender- Returns:
- this builder
-
withCc
Set the carbon copy address list. May be null.- Parameters:
cc
- the cc address list- Returns:
- this builder
-
withBcc
Set the blind carbon copy address list. May be null.- Parameters:
bcc
- the bcc address list- Returns:
- this builder
-
withDeliveryReceipt
Set to true to get a delivery receipt- Parameters:
deliveryReceipt
- the delivery receipt flag- Returns:
- this builder
-
withReadReceipt
Set to true to get a read receipt- Parameters:
readReceipt
- the read receipt flag- Returns:
- this builder
-
withHost
Set the SMTP host. Defaults to the value provided in the general configuration.- Parameters:
host
- the SMTP host- Returns:
- this builder
-
withPort
Set the SMTP port. Defaults to the value provided in the general configuration.- Parameters:
port
- the SMTP port- Returns:
- this builder
-
withSecurityProtocol
Set the security protocol ("starttls", "tlsssl"). May be null.- Parameters:
securityProtocol
- the security protocol- Returns:
- this builder
-
withUser
Set the SMTP user. Defaults to the value provided in the general configuration.- Parameters:
user
- the SMTP user- Returns:
- this builder
-
withPassword
Set the SMTP password. Defaults to the value provided in the general configuration.- Parameters:
password
- the STMP password- Returns:
- this builder
-
withSingleEmail
Set to true if a single email with all recipients should be sent. Defaults to false.- Parameters:
singleEmail
- the single email flag- Returns:
- this builder
-
withErrorReport
Set a list to get the send error report. The list will be populated with each recipient which the send failed.- Parameters:
errorReport
- teh error report list to fill- Returns:
- this builder
-
withInlineCSS
Set to true to inline CSS rules.
Set to false to preserve provided HTML code as is.
Default to true for legacy purposes.- Parameters:
inlineCSS
- the inlining CSS flag- Returns:
- this builder
-
withEmbeddedBase64Resources
Set to true to embed base64 resources as attachment.
Set to false to preserve provided HTML code as is.
Default to true.- Parameters:
embedBase64Resources
- the embedding flag- Returns:
- this builder
-
sendMail
Actually send mail.- Throws:
jakarta.mail.MessagingException
- If an error occurred while preparing or sending emailIOException
- if an error occurs while attaching a file.
-