public class MailSender extends Object
All mails that are queued are stored in a mail queue folder. This means that if you stop the e.g. server and restart it, no mail will be unsent. The worst that might happen is that a mail is sent twice (but this is a very thin chance to happen).
Constructor and Description |
---|
MailSender(MailProps pc,
ExecutorService executorService,
File mailQueueDirectory)
Creates a new instance of the mail sender with the specified settings.
|
Modifier and Type | Method and Description |
---|---|
Mail |
createMail()
Creates a new mail to send.
|
void |
deleteMailDirectory()
Deletes all unsent mails and the mail folder.
|
void |
dispose()
Disposes of the current mail sender and leaves unsent mail queued.
|
String |
getDescription()
Gets the description of this mail sender.
|
static MailSender |
getInstance()
Gets the default instance of the mail sender.
|
static MailSender |
getInstance(String name)
Gets the default instance of the mail sender.
|
static MailSender[] |
getInstances()
Returns all configured mail senders.
|
int |
getQueuedMailCount()
Returns how mail mails are currently queued for sending.
|
boolean |
isDisposed()
Checks if the mail sender is disposed of.
|
static int |
stopAll(long timeout)
Requests to stop all mail senders.
|
public MailSender(MailProps pc, ExecutorService executorService, File mailQueueDirectory) throws IOException, NoSuchProviderException, AddressException
pc
- The mail property container.executorService
- Executor service for mail sending, null when not queueing mails, just for test sending.mailQueueDirectory
- Mail queue directory. If it doesn't exist, it is created.IOException
- If the mail queue directory does not exist.NoSuchProviderException
- If the "smtp" or "smtps" providers do not exist!AddressException
- If the default sender failed to parse.public static MailSender getInstance()
public static MailSender getInstance(String name)
name
- The name of the mail sender, null for default.public static MailSender[] getInstances()
public static int stopAll(long timeout) throws InterruptedException
timeout
- Timeout in milliseconds to wait.InterruptedException
- If the wait is interrupted.public String getDescription()
public boolean isDisposed()
public Mail createMail()
public int getQueuedMailCount()
public void dispose()
public void deleteMailDirectory() throws IOException
IOException
- If the mail folder failed to be deleted.iizi® is a registered trademark of Mindus SARL. © Copyright Mindus SARL, 2020. All rights reserved.