Package org.ametys.core.util.mail
Class SendMailHelper.MailBuilder
- java.lang.Object
-
- org.ametys.core.util.mail.SendMailHelper.MailBuilder
-
- Enclosing class:
- SendMailHelper
public static class SendMailHelper.MailBuilder extends Object
Implements the builder pattern for creating and sending emails.
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidsendMail()Actually send mail.SendMailHelper.MailBuilderwithAsync(boolean async)If the mail should be sent asynchronously or not.SendMailHelper.MailBuilderwithAttachments(Collection<File> attachments)Set the optional attachments.SendMailHelper.MailBuilderwithBcc(List<String> bcc)Set the blind carbon copy address list.SendMailHelper.MailBuilderwithCc(List<String> cc)Set the carbon copy address list.SendMailHelper.MailBuilderwithDeliveryReceipt(boolean deliveryReceipt)Set to true to get a delivery receiptSendMailHelper.MailBuilderwithHost(String host)Set the SMTP host.SendMailHelper.MailBuilderwithHTMLBody(String htmlBody)Set the optional HTML body.SendMailHelper.MailBuilderwithInlineCSS(boolean inlineCSS)Set to true to inline CSS rules.SendMailHelper.MailBuilderwithPassword(String password)Set the SMTP password.SendMailHelper.MailBuilderwithPort(long port)Set the SMTP port.SendMailHelper.MailBuilderwithReadReceipt(boolean readReceipt)Set to true to get a read receiptSendMailHelper.MailBuilderwithRecipient(String recipient)Set the mail recipientSendMailHelper.MailBuilderwithRecipients(List<String> recipients)Set the mail recipientsSendMailHelper.MailBuilderwithSecurityProtocol(String securityProtocol)Set the security protocol ("starttls", "tlsssl").SendMailHelper.MailBuilderwithSender(String sender)Set the mail sender.SendMailHelper.MailBuilderwithSingleEmail(boolean singleEmail)Set to true if a single email with all recipients should be sent.SendMailHelper.MailBuilderwithSubject(String subject)Set the mail subject.SendMailHelper.MailBuilderwithTextBody(String textBody)Set the optional text body.SendMailHelper.MailBuilderwithUser(String user)Set the SMTP user.
-
-
-
Method Detail
-
withAsync
public SendMailHelper.MailBuilder withAsync(boolean async)
If the mail should be sent asynchronously or not.- Parameters:
async- the asynchronous flag- Returns:
- this builder
-
withSubject
public SendMailHelper.MailBuilder withSubject(String subject)
Set the mail subject. This parameter is mandatory.- Parameters:
subject- the mail subject- Returns:
- this builder
-
withHTMLBody
public SendMailHelper.MailBuilder withHTMLBody(String htmlBody)
Set the optional HTML body. May be null.- Parameters:
htmlBody- the HTML mail body- Returns:
- this builder
-
withTextBody
public SendMailHelper.MailBuilder withTextBody(String textBody)
Set the optional text body. May be null.- Parameters:
textBody- the text mail body- Returns:
- this builder
-
withAttachments
public SendMailHelper.MailBuilder withAttachments(Collection<File> attachments)
Set the optional attachments. May be null.- Parameters:
attachments- the file attachments- Returns:
- this builder
-
withRecipient
public SendMailHelper.MailBuilder withRecipient(String recipient)
Set the mail recipient- Parameters:
recipient- the recipient address- Returns:
- this builder
-
withRecipients
public SendMailHelper.MailBuilder withRecipients(List<String> recipients)
Set the mail recipients- Parameters:
recipients- the recipients addresses- Returns:
- this builder
-
withSender
public SendMailHelper.MailBuilder withSender(String sender)
Set the mail sender.- Parameters:
sender- the mail sender- Returns:
- this builder
-
withCc
public SendMailHelper.MailBuilder withCc(List<String> cc)
Set the carbon copy address list. May be null.- Parameters:
cc- the cc address list- Returns:
- this builder
-
withBcc
public SendMailHelper.MailBuilder withBcc(List<String> bcc)
Set the blind carbon copy address list. May be null.- Parameters:
bcc- the bcc address list- Returns:
- this builder
-
withDeliveryReceipt
public SendMailHelper.MailBuilder withDeliveryReceipt(boolean deliveryReceipt)
Set to true to get a delivery receipt- Parameters:
deliveryReceipt- the delivery receipt flag- Returns:
- this builder
-
withReadReceipt
public SendMailHelper.MailBuilder withReadReceipt(boolean readReceipt)
Set to true to get a read receipt- Parameters:
readReceipt- the read receipt flag- Returns:
- this builder
-
withHost
public SendMailHelper.MailBuilder withHost(String host)
Set the SMTP host. Defaults to the value provided in the general configuration.- Parameters:
host- the SMTP host- Returns:
- this builder
-
withPort
public SendMailHelper.MailBuilder withPort(long port)
Set the SMTP port. Defaults to the value provided in the general configuration.- Parameters:
port- the SMTP port- Returns:
- this builder
-
withSecurityProtocol
public SendMailHelper.MailBuilder withSecurityProtocol(String securityProtocol)
Set the security protocol ("starttls", "tlsssl"). May be null.- Parameters:
securityProtocol- the security protocol- Returns:
- this builder
-
withUser
public SendMailHelper.MailBuilder withUser(String user)
Set the SMTP user. Defaults to the value provided in the general configuration.- Parameters:
user- the SMTP user- Returns:
- this builder
-
withPassword
public SendMailHelper.MailBuilder withPassword(String password)
Set the SMTP password. Defaults to the value provided in the general configuration.- Parameters:
password- the STMP password- Returns:
- this builder
-
withSingleEmail
public SendMailHelper.MailBuilder withSingleEmail(boolean singleEmail)
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
-
withInlineCSS
public SendMailHelper.MailBuilder withInlineCSS(boolean inlineCSS)
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
-
sendMail
public void sendMail() throws jakarta.mail.MessagingException, IOException
Actually send mail.- Throws:
jakarta.mail.MessagingException- If an error occurred while preparing or sending emailIOException- if an error occurs while attaching a file.
-
-