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 ClassesNested classes/interfaces inherited from class org.jgrapes.mail.MailConnectionManager
MailConnectionManager.AbstractMailChannelNested classes/interfaces inherited from class org.jgrapes.io.util.ConnectionManager
ConnectionManager.ConnectionNested classes/interfaces inherited from interface org.jgrapes.core.Channel
Channel.Default -
Field Summary
Fields inherited from class org.jgrapes.mail.MailConnectionManager
mailPropsFields inherited from class org.jgrapes.io.util.ConnectionManager
connections -
Constructor Summary
ConstructorsConstructorDescriptionMailSender(Channel componentChannel) Creates a new component base with its channel set to the given channel. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidconfigureComponent(Map<String, String> values) Configure the component specific values.protected booleanIf 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.voidonMessage(SendMailMessage event, Channel channel) Sends the message as specified by the event.voidonOpenMailSender(OpenMailSender event, Channel channel) Open a connection for sending mail as specified by the event.voidStart 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, setPasswordMethods inherited from class org.jgrapes.io.util.ConnectionManager
executorService, onClose, onStop, setExecutorServiceMethods inherited from class org.jgrapes.core.Component
channel, component, defaultCriterion, isEligibleFor, setNameMethods 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, unregisterAsGeneratorMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods 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.SELFcan 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:ConnectionManagerIf 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:
connectionsGeneratein classConnectionManager<MailSender.SenderChannel>- Returns:
- true, if connections generate
-
setMailProperties
Sets the mail properties.See the Jakarta Mail documentation for available settings.
- Overrides:
setMailPropertiesin 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:MailConnectionManagerConfigure the component specific values.- Specified by:
configureComponentin 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
-