Package com.iizix.mail
Class MailSender
java.lang.Object
com.iizix.mail.MailSender
The mail sender can send emails directly or queued, with a reply callback. It must be configured in either the Designer or the Server.
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).
- Author:
- Christopher Mindus
- Constructor SummaryConstructorsConstructorDescription- MailSender- (MailProps pc, ExecutorService executorService, File mailQueueDirectory) Creates a new instance of the mail sender with the specified settings.
- Method SummaryModifier and TypeMethodDescriptionCreates a new mail to send.Creates a new mail to send with all defaults that are defined set: Sender, Reply To (initialized using- Message.setReplyTo(Address []), CC's, and BCC's.- voidDeletes all unsent mails and the mail folder.- void- dispose()Disposes of the current mail sender and leaves unsent mail queued.The default BCC's for mails.The default CC's for mails.The default 'Reply To' for mails.The default 'Sender' for mails.Gets the description of this mail sender.- static MailSenderGets the default instance of the mail sender.- static MailSender- getInstance- (String name) Gets the default instance of the mail sender.- static MailSender[]Returns all configured mail senders.- intReturns how mail mails are currently queued for sending.- booleanChecks if the mail sender is disposed of.- static int- stopAll- (long timeout) Requests to stop all mail senders.
- Constructor Details- MailSenderpublic MailSender- (MailProps pc, ExecutorService executorService, File mailQueueDirectory) throws IOException, NoSuchProviderException, AddressException Creates a new instance of the mail sender with the specified settings. Any previous mail sender with remaining messages to send will still do its work.- Parameters:
- 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.
- Throws:
- 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.
 
 
- Method Details- getInstanceGets the default instance of the mail sender.- Returns:
- The default instance, null if none is configured.
 
- getInstanceGets the default instance of the mail sender.- Parameters:
- name- The name of the mail sender, null for default.
- Returns:
- The default instance, null if none is configured.
 
- getInstancesReturns all configured mail senders.- Returns:
- The array may be empty if no mail senders are configured.
 
- stopAllRequests to stop all mail senders.- Parameters:
- timeout- Timeout in milliseconds to wait.
- Returns:
- Number of mails left to send (in all mail queues), zero means none.
- Throws:
- InterruptedException- If the wait is interrupted.
 
- getDescriptionGets the description of this mail sender.- Returns:
- A description string, or null if none is defined.
 
- getDefaultSenderThe default 'Sender' for mails.- Returns:
- The default 'Sender' for mails, nullfor none.
 
- getDefaultReplyToThe default 'Reply To' for mails.- Returns:
- The default 'Reply To' for mails, nullfor none.
 
- getDefaultCCsThe default CC's for mails.- Returns:
- The default CC's for mails, nullfor none.
 
- getDefaultBCCsThe default BCC's for mails.- Returns:
- The default BCC's for mails, nullfor none.
 
- isDisposedpublic boolean isDisposed()Checks if the mail sender is disposed of.- Returns:
- true if disposed of, false otherwise.
 
- createMailCreates a new mail to send.- Returns:
- An uninitialized mail with a MimeMessageas the mail's message. It can be retrieved usingMail.getMessage()and then cast toMimeMessage.
 
- createMailWithDefaultsCreates a new mail to send with all defaults that are defined set:- Sender,
- Reply To (initialized using Message.setReplyTo(Address []),
- CC's, and
- BCC's.
 - Returns:
- An new mail initialized only with default Sender, Reply To, CC's and BCC's where defined, with a MimeMessageas the mail's message. It can be retrieved usingMail.getMessage()and then cast toMimeMessage.
- Throws:
- MessagingException- For messaging failures.
 
- getQueuedMailCountpublic int getQueuedMailCount()Returns how mail mails are currently queued for sending.- Returns:
- The number of queued mails.
 
- disposepublic void dispose()Disposes of the current mail sender and leaves unsent mail queued.
- deleteMailDirectoryDeletes all unsent mails and the mail folder. This call should be made in preference once the mail sender has been disposed of.- Throws:
- IOException- If the mail folder failed to be deleted.