Package org.jgrapes.mail
Class MailSender
- All Implemented Interfaces:
Iterable<ComponentType>
,Channel
,ComponentType
,Eligible
,Manager
A component that sends mail using a system wide or user specific
connection.
The system wide connection is created upon the start of the component.
Additional connections can be created by firing events of type
OpenMailSender
.
-
Nested Class Summary
Nested classes/interfaces inherited from class org.jgrapes.mail.MailConnectionManager
MailConnectionManager.AbstractMailChannel
Nested classes/interfaces inherited from class org.jgrapes.io.util.ConnectionManager
ConnectionManager.Connection
Nested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default
-
Field Summary
Fields inherited from class org.jgrapes.mail.MailConnectionManager
mailProps
Fields inherited from class org.jgrapes.io.util.ConnectionManager
connections
-
Constructor Summary
ConstructorDescriptionMailSender
(Channel componentChannel) Creates a new component base with its channel set to the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
configureComponent
(Map<String, String> values) Configure the component specific values.protected boolean
If connections are event generators, register the component as generator upon the creation of the first connection and unregister it when closing the last one.Returns the max idle time.void
onMessage
(SendMailMessage event, Channel channel) Sends the message as specified by the event.void
onOpenMailSender
(OpenMailSender event, Channel channel) Open a connection for sending mail as specified by the event.void
Start the component.setMailProperties
(Map<String, String> props) Sets the mail properties.setMaxIdleTime
(Duration maxIdleTime) Sets the maximum idle time.Methods inherited from class org.jgrapes.mail.MailConnectionManager
onConfigUpdate, password, setPassword
Methods inherited from class org.jgrapes.io.util.ConnectionManager
executorService, onClose, onStop, setExecutorService
Methods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setName
Methods inherited from class org.jgrapes.core.internal.ComponentVertex
activeEventPipeline, addHandler, attach, channelReplacements, children, componentPath, componentVertex, detach, fire, initComponentsHandlers, iterator, name, newEventPipeline, newEventPipeline, parent, registerAsGenerator, root, toString, unregisterAsGenerator
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
MailSender
Creates a new component base with its channel set to the given channel.As a special case
Channel.SELF
can be passed to the constructor to make the component use itself as channel. The special value is necessary as you obviously cannot pass an object to be constructed to its constructor.- Parameters:
componentChannel
- the channel that the component’s handlers listen on by default and thatManager.fire(Event, Channel...)
sends the event to
-
-
Method Details
-
connectionsGenerate
Description copied from class:ConnectionManager
If connections are event generators, register the component as generator upon the creation of the first connection and unregister it when closing the last one.- Specified by:
connectionsGenerate
in classConnectionManager<MailSender.SenderChannel>
- Returns:
- true, if connections generate
-
setMailProperties
Sets the mail properties.See the Jakarta Mail documentation for available settings.
- Overrides:
setMailProperties
in classMailConnectionManager<MailSender.SenderChannel,
Event<?>> - Parameters:
props
- the props- Returns:
- the mail monitor
-
setMaxIdleTime
Sets the maximum idle time.An open connection to the mail server is closed after this time.
- Parameters:
maxIdleTime
- the new max idle time
-
maxIdleTime
Returns the max idle time.- Returns:
- the duration
-
configureComponent
Description copied from class:MailConnectionManager
Configure the component specific values.- Specified by:
configureComponent
in classMailConnectionManager<MailSender.SenderChannel,
Event<?>> - Parameters:
values
- the values
-
onStart
Start the component.- Parameters:
event
- the event- Throws:
MessagingException
-
onOpenMailSender
@Handler public void onOpenMailSender(OpenMailSender event, Channel channel) throws MessagingException Open a connection for sending mail as specified by the event.Properties configured for the component are used as fallbacks, so simply sending an event without specific properties opens another system connection.
- Parameters:
event
- the eventchannel
- the channel- Throws:
MessagingException
-
onMessage
Sends the message as specified by the event.- Parameters:
event
- the event- Throws:
MessagingException
- the messaging exception
-