Package com.groiss.util
Class MailSender
java.lang.Object
com.groiss.util.MailSender
Use the methods in this class for sending SMTP mails.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
MailAction defines the action for the mail. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Activate logging of this senders session to a Stream.Get the contents of the debugging stream.static MailSender
Returns a default MailSender which properties are taken from configuration: SMTP host under Configuration/Communication Mail sender under Configuration/Communication SMTP Username under Configuration/Communication SMTP Password under Configuration/Communication Type of SMTP communication under Configuration/CommunicationMailSender.MailAction
defined under Configuration/Communication MailQueue is allowedgetHost()
return the smtp hoststatic MailSender.MailAction
Get mail action from configurationReturns aMailQueueItem
which could be set after sending mailHINT: UseMessageTemplate
interface!int
getPort()
return the sender addressGet the sender credentialsstatic MailSender
Returns a MailSender which properties are taken from a mailbox.boolean
determine, if mail queue should be usedvoid
setCommunicationType
(String type) Sets the communication type.void
set default mailsender properties defined in configuration Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.void
Set mailsender properties as defined for a mailbox Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.void
setDefaultProps
(Properties props) void
setMailAction
(MailSender.MailAction action) Sets anotherMailSender.MailAction
void
set mailsender properties from mailbox data.void
set mailsender properties from mailbox data.void
Sets an alternative sender.void
setSenderAndCredentials
(String mailAddress, String uname, String passwd) Sets alternative sender credentials.void
setSMTPHost
(String smtphost) Sets alternative SMTP host (+ optionally SMTP port, separated by colon).
-
Method Details
-
getDefaultSender
Returns a default MailSender which properties are taken from configuration:- SMTP host under Configuration/Communication
- Mail sender under Configuration/Communication
- SMTP Username under Configuration/Communication
- SMTP Password under Configuration/Communication
- Type of SMTP communication under Configuration/Communication
MailSender.MailAction
defined under Configuration/Communication- MailQueue is allowed
- Returns:
- the MailSender
-
getSenderForMailBox
Returns a MailSender which properties are taken from a mailbox. If no smtphost is specified for the mailbox, the default sendergetDefaultSender()
is returned.- SMTP hostfrom mailbox
- Mail senderfrom mailbox
- SMTP Usernamefrom mailbox
- SMTP Passwordfrom mailbox, or the OAuth access token, if an authorizer is specified at the mailbox
- Type of SMTP communicationfrom mailbox
MailSender.MailAction
defined under Configuration/Communication- MailQueue is allowed
- Parameters:
mb
- the mailbox- Returns:
- the MailSender
-
isMailQueueAllowed
public boolean isMailQueueAllowed()determine, if mail queue should be used -
getCommunicationType
- Returns:
- the communicationType
-
setCommunicationType
Sets the communication type. Allowed only, ifMailSender.MailAction
is NO_QUEUE! -
getHost
return the smtp host -
getSender
return the sender address -
getMessage
HINT: UseMessageTemplate
interface!- Returns:
- the last message sent by one of this MailSender send-methods
-
getPort
public int getPort()- Returns:
- the configured SMTP Port
-
setSender
Sets an alternative sender.- Parameters:
mailAddress
-
-
getSenderCredentials
Get the sender credentials- Returns:
- a Pair of username/password
-
setSenderAndCredentials
Sets alternative sender credentials.- Parameters:
mailAddress
- the mail address of useruname
- the user namepasswd
- the password of given user
-
setSMTPHost
Sets alternative SMTP host (+ optionally SMTP port, separated by colon). Allowed only, ifMailSender.MailAction
is NO_QUEUE!- Parameters:
smtphost
-
-
setMailAction
Sets anotherMailSender.MailAction
-
getMailAction
- Returns:
- the current
MailSender.MailAction
-
getMailQueueItem
Returns aMailQueueItem
which could be set after sending mail- Returns:
- the
MailQueueItem
, otherwisenull
-
getUserOrMailbox
-
getSession
- Returns:
-
setPropsFromMailBox
set mailsender properties from mailbox data. Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.- Parameters:
mb
- - the mailbox which mailadress (and credentials) should be used as sender
-
setPropsFromUser
set mailsender properties from mailbox data. Mails can be only put into the mailqueue if they are send by default, mailbox or user properties.- Parameters:
u
- - the u which mailadress (and mail credentials) should be used as sender
-
setDefaultProps
public void setDefaultProps()set default mailsender properties defined in configuration Mails can be only put into the mailqueue if they are send by default, mailbox or user properties. -
setDefaultProps
Set mailsender properties as defined for a mailbox Mails can be only put into the mailqueue if they are send by default, mailbox or user properties. -
setDefaultProps
-
getMailActionFromConfiguration
Get mail action from configuration- Returns:
- the mail action
-
activateDebugStream
public void activateDebugStream()Activate logging of this senders session to a Stream. Must be called before construction of the mail session takes place. The contents of the stream can afterwards be obtained by callinggetDebugStreamContents()
. -
getDebugStreamContents
Get the contents of the debugging stream. Must have been activated viaactivateDebugStream()
.- Returns:
- the contents of the stream or null
-