Examples of MailHandler


Examples of com.sun.mail.util.logging.MailHandler

     * On close any remaining records are discarded because they never reach
     * the mail handler.
     */
    private static void initPushNormal() {
        final int capacity = 3;
        final MailHandler h = new MailHandler(capacity);
        h.setSubject("Push normal demo");
        MemoryHandler m = new MemoryHandler(h, capacity, Level.WARNING) {

            public void push() {
                super.push()//push to target.
                super.flush(); //make the target send the email.
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

     *  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}")});
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

        return MessageFormat.format(pattern, new Object[]{new Long(count), new Long(errors)});
    }

    private String extFrom(Handler h) {
        if(h instanceof MailHandler) {
            MailHandler mh = (MailHandler)h;
            Formatter[] content = mh.getAttachmentFormatters();
            Formatter[] names = mh.getAttachmentNames();
            assert content.length == names.length;
            for(int i=0; i<content.length; i++) {
                if(names[i] == this) {
                    if(content[i] instanceof XMLFormatter) {
                        return ".xml";
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

    /**
     * Example for body only messages.
     * On close the remaining messages are sent.
     */
    private static void initBodyOnly() {
        MailHandler h = new MailHandler();
        h.setSubject("Body only demo");
        LOGGER.addHandler(h);
    }
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

     * will format and send the current records.  Capacity is used to roughly
     * limit the size of an outgoing message.
     * On close any remaining messages are sent.
     */
    private static void initLowCapacity() {
        MailHandler h = new MailHandler(5);
        h.setSubject("Low capacity demo");
        LOGGER.addHandler(h);
    }
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

    /**
     * Example for body only messages.
     * On close any remaining messages are sent.
     */
    private static void initSimpleAttachment() {
        MailHandler h = new MailHandler();
        h.setSubject("Body and attachment demo");
        h.setAttachmentFormatters(new Formatter[]{new XMLFormatter()});
        h.setAttachmentNames(new String[]{"data.xml"});
        LOGGER.addHandler(h);
    }
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

     * Example setup for priority messages by level.
     * If the push level is triggered the message is high priority.
     * Otherwise, on close any remaining messages are sent.
     */
    private static void initWithPushLevel() {
        MailHandler h = new MailHandler();
        h.setSubject("Push level demo");
        h.setPushLevel(Level.WARNING);
        LOGGER.addHandler(h);
    }
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

     * Example for priority messages by custom trigger.
     * If the push filter is triggered the message is high priority.
     * Otherwise, on close any remaining messages are sent.
     */
    private static void initWithPushFilter() {
        MailHandler h = new MailHandler();
        h.setSubject("Push on MessagingException demo");
        h.setPushLevel(Level.ALL);
        h.setPushFilter(new MessageErrorsFilter(true));
        LOGGER.addHandler(h);
    }
View Full Code Here

Examples of com.sun.mail.util.logging.MailHandler

     * the mail handler.
     */
    private static void initPushOnly() {
        final int capacity = 3;
        final Level pushLevel = Level.WARNING;
        final MailHandler h = new MailHandler(capacity);
        h.setPushLevel(pushLevel);
        h.setSubject("Push only demo");
        MemoryHandler m = new MemoryHandler(h, capacity, pushLevel);
        h.setLevel(m.getLevel());
        LOGGER.addHandler(m);
        pushOnlyHandler = h;
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.