* Example for various kinds of custom sorting, formatting, and filtering
* for multiple attachment messages.
* On close any remaining messages are sent.
*/
private static void initCustomAttachments() {
MailHandler h = new MailHandler();
//Sort records by level keeping the severe messages at the top.
h.setComparator(new LevelAndSeqComparator(true));
//Use subject to provide a hint as to what is in the email.
h.setSubject(new SummaryNameFormatter("Log containing {0} records with {1} errors."));
//Make the body give a simple summary of what happened.
h.setFormatter(new SummaryFormatter());
//Create 3 attachments.
h.setAttachmentFormatters(new Formatter[]{new XMLFormatter(), new XMLFormatter(), new SimpleFormatter()});
//filter each attachment differently.
h.setAttachmentFilters(new Filter[]{null, new MessageErrorsFilter(false),
new MessageErrorsFilter(true)});
//create simple names.
h.setAttachmentNames(new String[]{"all.xml", "errors.xml", "errors.txt"});
//extract simple name, replace the rest with formatters.
h.setAttachmentNames(new Formatter[]{h.getAttachmentNames()[0],
new SummaryNameFormatter("{0} records and {1} mail errors"),
new SummaryNameFormatter("{0,choice,0#no records|1#1 record|" +
"1<{0,number,integer} records} and " +
"{1,choice,0#no errors|1#1 error|1<" +
"{1,number,integer} errors}")});