Copyright© 2008-2022 Sitevision AB, all rights reserved.
@Requireable(value="MailBuilder") public interface MailBuilder extends Builder<Mail>
An instance of the Sitevision class implementing this interface can be obtained via
MailUtil.getMailBuilder()
.
See MailUtil
for how to obtain an instance of the MailUtil
interface.
MailBuilder has some mandatory attributes:
MailBuilder also has some optional attributes:
null
.
null
.
null
.
Note that there are three types of recipients (TO, CC, BCC). This builder will not detect or automatically handle duplicates cross types. It is up to the mail builder user to ensure addresses aren't added as different types of recipients.
Using the MailBuilder is pretty straightforward, if you remember that it is stateful. Conceptually you would typically use it like this:
When you have built a Mail
instance, you can re-use the MailBuilder to build more instances. Something like:
Example of how this strategy could be implemented in Velocity:
(send one "personalized" mail to Magnus and one to Mikael)
## Get the mail util and the mail builder
#set ($mailUtil = $sitevisionUtils.mailUtil)
#set ($mailBuilder = $mailUtil.mailBuilder)
## Create a mail
#set ($mail = $mailBuilder.setSubject('Hello buddy'
).setTextMessage('How are you Magnus?'
).addRecipient('magnus.lovgren@sitevision.se'
).build())
## Send mail
#if ($mail.send())
<p>Mail to Magnus successfully sent!</p>
#else
<p>Mail to Magnus could <strong>not</strong> be sent!</p>
#end
## Create another mail
#set ($mail = $mailBuilder.setTextMessage('How are you Mikael?'
).clearRecipients().addRecipient('mikael.wikblom@sitevision.se'
).build())
## Send mail
#if ($mail.send())
<p>Mail to Mikael successfully sent!</p>
#else
<p>Mail to Mikael could <strong>not</strong> be sent!</p>
#end
Tip! The Builder interface documentation
contains
more information about Builders and how to work with them!
Modifier and Type | Method and Description |
---|---|
MailBuilder |
addBlindCopyRecipient(String aBlindCopyRecipientAddress)
Adds a blind carbon copy recipient address (BCC).
|
MailBuilder |
addCopyRecipient(String aCopyRecipientAddress)
Adds a carbon copy recipient address (CC).
|
MailBuilder |
addRecipient(String aRecipientAddress)
Adds a recipient address (TO).
|
MailBuilder |
addReplyTo(String aReplyToAddress)
Adds a reply-to address.
|
Mail |
build()
Creates a Mail instance using current state of this builder.
|
MailBuilder |
clearAllRecipients()
Convenience method for removing all addresses for all recipient types (TO/CC/BCC).
|
MailBuilder |
clearBlindCopyRecipients()
Removes all previously added blind carbon copy recipient addresses (BCC).
|
MailBuilder |
clearCopyRecipients()
Removes all previously added carbon copy recipient addresses (CC).
|
MailBuilder |
clearRecipients()
Removes all previously added recipient addresses (TO).
|
MailBuilder |
clearReplyTos()
Removes all previously added reply-to addresses.
|
MailBuilder |
setFrom(String aFromAddress)
Sets the from address.
|
MailBuilder |
setHtmlMessage(String aHtmlMessage)
Sets the html message.
|
MailBuilder |
setSubject(String aSubject)
Sets the subject.
|
MailBuilder |
setTextMessage(String aTextMessage)
Sets the text message.
|
MailBuilder setFrom(String aFromAddress)
aFromAddress
- the from address. A whitespace-only address will be ignored, default (null) will be set instead.MailBuilder addReplyTo(String aReplyToAddress)
aReplyToAddress
- a reply-to address. A null or whitespace-only address will be ignored.MailBuilder clearReplyTos()
MailBuilder setSubject(String aSubject)
aSubject
- a subjectMailBuilder setTextMessage(String aTextMessage)
aTextMessage
- a text messageMailBuilder setHtmlMessage(String aHtmlMessage)
aHtmlMessage
- a html messageMailBuilder addRecipient(String aRecipientAddress)
aRecipientAddress
- a recipient address. A null or whitespace-only address will be ignored.MailBuilder clearRecipients()
MailBuilder clearAllRecipients()
clearRecipients()
,
clearCopyRecipients()
,
clearBlindCopyRecipients()
MailBuilder addCopyRecipient(String aCopyRecipientAddress)
aCopyRecipientAddress
- a carbon copy recipient address. A null or whitespace-only address will be ignored.MailBuilder clearCopyRecipients()
MailBuilder addBlindCopyRecipient(String aBlindCopyRecipientAddress)
aBlindCopyRecipientAddress
- a blind carbon copy recipient address. A null or whitespace-only address will be ignored.MailBuilder clearBlindCopyRecipients()
Mail build() throws IllegalStateException
build
in interface Builder<Mail>
IllegalStateException
- will be thrown if subject is null, if there are no recipients or
if a recipient address is invalid, if the from address, a copy address, blind copy address or reply-to address is invalid.Sitevision - Portal and Content Management Made Easy
Sitevision is an advanced Java enterprise portal product and a portlet container (JSR 286) that implements Java Content Repository (JSR 283).
Copyright© 2008-2022 Sitevision AB, all rights reserved.