Package org.apache.cocoon.mail

Examples of org.apache.cocoon.mail.MailSender


                   Parameters parameters)
    throws Exception {
        boolean success = false;
        Map status = null;

        MailSender mms = null;
        try {
            Request request = ObjectModelHelper.getRequest(objectModel);

            // FIXME Remove support of old smtphost parameter
            String smtpHost = parameters.getParameter("smtp-host", parameters.getParameter("smtphost", this.smtpHost));
            String smtpUser = parameters.getParameter("smtp-user", this.smtpUser);
            String smtpPassword = parameters.getParameter("smtp-password", this.smtpPassword);

            // Empty parameter means absent parameter
            if ("".equals(smtpHost)) {
                smtpHost = this.smtpHost;
            }
            if ("".equals(smtpUser)) {
                smtpUser = this.smtpUser;
            }
            if ("".equals(smtpPassword)) {
                smtpPassword = this.smtpPassword;
            }

            mms = (MailSender) this.manager.lookup(MailSender.ROLE);

            // Initialize non-default session if host or user specified.
            if (smtpHost != null || smtpUser != null) {
                mms.setSmtpHost(smtpHost, smtpUser, smtpPassword);
            }

            if (parameters.isParameter("from")) {
                mms.setFrom(parameters.getParameter("from", null));
            }
            if (parameters.isParameter("to")) {
                mms.setTo(parameters.getParameter("to", null));
            }
            if (parameters.isParameter("replyTo")) {
                mms.setReplyTo(parameters.getParameter("replyTo", null));
            }
            if (parameters.isParameter("cc")) {
                mms.setCc(parameters.getParameter("cc", null));
            }
            if (parameters.isParameter("bcc")) {
                mms.setBcc(parameters.getParameter("bcc", null));
            }
            if (parameters.isParameter("subject")) {
                mms.setSubject(parameters.getParameter("subject", null));
            }

            String bodyURL = parameters.getParameter("src", "");
            String body = parameters.getParameter("body", "");
            if (bodyURL.length() > 0) {
                String type = null;
                if (parameters.isParameter("srcMimeType")) {
                    type = parameters.getParameter("srcMimeType", null);
                }
                mms.setBodyURL(bodyURL, type);
            } else if (body.length() > 0) {
                String type = null;
                String charset = parameters.getParameter("charset", "");
                if (charset.length() > 0) {
                    type = "text/plain; charset=" + charset;
                }
                mms.setBody(body, type);
            }

            if (parameters.isParameter("attachments")) {
                String fileName[] = StringUtils.split(parameters.getParameter("attachments"));
                for (int i = 0; i < fileName.length; i++) {
                    String srcName = fileName[i];

                    if (srcName.indexOf(":") == -1) {
                        Object obj = request.get(srcName);
                        mms.addAttachment(obj);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("request-attachment: " + obj);
                        }
                    } else {
                        mms.addAttachmentURL(srcName);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("sitemap-attachment: " + srcName);
                        }
                    }
                }
            }

            mms.send();

            success = true;
            status = new HashMap(3);
            status.put(Sendmail.STATUS, "success");
View Full Code Here


        Parameters parameters)
        throws Exception {
        boolean success = false;
        Map status = null;

        MailSender mms = null;
        try {
            if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("SendmailAction: act start");
            }

            Request request = ObjectModelHelper.getRequest(objectModel);

            if (parameters.isParameter("smtphost")) {
                smtpHost = parameters.getParameter("smtphost", null);

                if (this.getLogger().isDebugEnabled()) {
                    getLogger().debug(
                        "SendmailAction: overriding default smtp server, using "
                            + smtpHost);
                }
            }

            mms = (MailSender) this.manager.lookup(MailSender.ROLE);
            if (smtpHost != null) {
              mms.setSmtpHost(smtpHost);
            }

            if (parameters.isParameter("from")) {
                mms.setFrom(parameters.getParameter("from", null));
            }

            if (parameters.isParameter("to")) {
                mms.setTo(parameters.getParameter("to", null));
            }

            if (parameters.isParameter("cc")) {
                mms.setCc(parameters.getParameter("cc", null));
            }

            if (parameters.isParameter("bcc")) {
                mms.setBcc(parameters.getParameter("bcc", null));
            }

            if (parameters.isParameter("subject")) {
                mms.setSubject(parameters.getParameter("subject", null));
            }

            if (parameters.isParameter("charset")) {
                mms.setCharset(parameters.getParameter("charset", null));
            }

            if (parameters.isParameter("src")) {
                mms.setBodyFromSrc(parameters.getParameter("src", null));
                if (parameters.isParameter("srcMimeType")) {
                    mms.setBodyFromSrcMimeType(
                        parameters.getParameter("srcMimeType", null));
                }
            } else if (parameters.isParameter("body")) {
                mms.setBody(parameters.getParameter("body", null));
            }

            if (parameters.isParameter("attachments")) {
                String fileName[] = StringUtils.split(parameters.getParameter("attachments"));
                for (int i = 0; i < fileName.length; i++) {
                    String srcName = fileName[i];

                    if (srcName.indexOf(":") == -1) {
                        Object obj = request.get(srcName);
                        mms.addAttachment(obj);
                        if (this.getLogger().isDebugEnabled()) {
                            getLogger().debug("request-attachment: " + obj);
                        }
                    } else {
                        mms.addAttachmentURL(
                            srcName,
                            null,
                            srcName.substring(srcName.lastIndexOf('/') + 1));
                        if (this.getLogger().isDebugEnabled()) {
                            getLogger().debug("sitemap-attachment: " + srcName);
                        }
                    }
                }
            }

            mms.send(resolver);

            if (this.getLogger().isDebugEnabled()) {
                getLogger().debug("SendmailAction: act stop");
            }
View Full Code Here

            getLogger().error("Can't send mails - no MailSender service found.");
            return;
        }

        Identifiable sender = translatedMessage.getSender();
        MailSender mailer = null;
        try {
            mailer = (MailSender) this.manager.lookup(MailSender.ROLE);
            if (this.username == null) {
                mailer.setSmtpHost(this.smtpHost);
            } else {
                mailer.setSmtpHost(this.smtpHost, this.username, this.password);
            }

            mailer.setTo(recipient.getEmail());
            if (sender instanceof User) {
                mailer.setFrom(((User) sender).getEmail());
            }

            mailer.setSubject(translatedMessage.getSubject());
            mailer.setBody(translatedMessage.getBody(), "text/plain; charset=UTF-8");
            mailer.send();
       
        } catch (AddressException e) {
            getLogger().error("Sending mail failed (address error): ", e);
            throw new NotificationException(e);
        } catch (MessagingException e) {
View Full Code Here

                   Parameters parameters)
    throws Exception {
        boolean success = false;
        Map status = null;

        MailSender mms = null;
        try {
            Request request = ObjectModelHelper.getRequest(objectModel);

            // FIXME Remove support of old smtphost parameter
            String smtpHost = parameters.getParameter("smtp-host", parameters.getParameter("smtphost", this.smtpHost));
            String smtpUser = parameters.getParameter("smtp-user", this.smtpUser);
            String smtpPassword = parameters.getParameter("smtp-password", this.smtpPassword);

            // Empty parameter means absent parameter
            if ("".equals(smtpHost)) {
                smtpHost = this.smtpHost;
            }
            if ("".equals(smtpUser)) {
                smtpUser = this.smtpUser;
            }
            if ("".equals(smtpPassword)) {
                smtpPassword = this.smtpPassword;
            }

            mms = (MailSender) this.manager.lookup(MailSender.ROLE);

            // Initialize non-default session if host or user specified.
            if (smtpHost != null || smtpUser != null) {
                mms.setSmtpHost(smtpHost, smtpUser, smtpPassword);
            }

            if (parameters.isParameter("from")) {
                mms.setFrom(parameters.getParameter("from", null));
            }
            if (parameters.isParameter("to")) {
                mms.setTo(parameters.getParameter("to", null));
            }
            if (parameters.isParameter("replyTo")) {
                mms.setReplyTo(parameters.getParameter("replyTo", null));
            }
            if (parameters.isParameter("cc")) {
                mms.setCc(parameters.getParameter("cc", null));
            }
            if (parameters.isParameter("bcc")) {
                mms.setBcc(parameters.getParameter("bcc", null));
            }
            if (parameters.isParameter("subject")) {
                mms.setSubject(parameters.getParameter("subject", null));
            }
            if (parameters.isParameter("charset")) {
                mms.setCharset(parameters.getParameter("charset", null));
            }

            if (parameters.isParameter("src")) {
                mms.setBodyFromSrc(parameters.getParameter("src", null));
                if (parameters.isParameter("srcMimeType")) {
                    mms.setBodyFromSrcMimeType(
                        parameters.getParameter("srcMimeType", null));
                }
            } else if (parameters.isParameter("body")) {
                mms.setBody(parameters.getParameter("body", null));
            }

            if (parameters.isParameter("attachments")) {
                String fileName[] = StringUtils.split(parameters.getParameter("attachments"));
                for (int i = 0; i < fileName.length; i++) {
                    String srcName = fileName[i];

                    if (srcName.indexOf(":") == -1) {
                        Object obj = request.get(srcName);
                        mms.addAttachment(obj);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("request-attachment: " + obj);
                        }
                    } else {
                        mms.addAttachmentURL(srcName,
                                             null,
                                             srcName.substring(srcName.lastIndexOf('/') + 1));
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("sitemap-attachment: " + srcName);
                        }
                    }
                }
            }

            mms.send();

            success = true;
            status = new HashMap(3);
            status.put(Sendmail.STATUS, "success");
View Full Code Here

                   Parameters parameters)
    throws Exception {
        boolean success = false;
        Map status = null;

        MailSender mms = null;
        try {
            if (getLogger().isDebugEnabled()) {
                getLogger().debug("act start");
            }

            Request request = ObjectModelHelper.getRequest(objectModel);

            // FIXME Remove support of old smtphost parameter
            String smtpHost = parameters.getParameter("smtp-host", parameters.getParameter("smtphost", this.smtpHost));
            String smtpUser = parameters.getParameter("smtp-user", this.smtpUser);
            String smtpPassword = parameters.getParameter("smtp-password", this.smtpPassword);

            // Empty parameter means absent parameter
            if ("".equals(smtpHost)) {
                smtpHost = this.smtpHost;
            }
            if ("".equals(smtpUser)) {
                smtpUser = this.smtpUser;
            }
            if ("".equals(smtpPassword)) {
                smtpPassword = this.smtpPassword;
            }

            mms = (MailSender) this.manager.lookup(MailSender.ROLE);

            // Initialize non-default session if host or user specified.
            if (smtpHost != null || smtpUser != null) {
                mms.setSmtpHost(smtpHost, smtpUser, smtpPassword);
            }

            if (parameters.isParameter("from")) {
                mms.setFrom(parameters.getParameter("from", null));
            }
            if (parameters.isParameter("to")) {
                mms.setTo(parameters.getParameter("to", null));
            }
            if (parameters.isParameter("cc")) {
                mms.setCc(parameters.getParameter("cc", null));
            }
            if (parameters.isParameter("bcc")) {
                mms.setBcc(parameters.getParameter("bcc", null));
            }
            if (parameters.isParameter("subject")) {
                mms.setSubject(parameters.getParameter("subject", null));
            }
            if (parameters.isParameter("charset")) {
                mms.setCharset(parameters.getParameter("charset", null));
            }

            if (parameters.isParameter("src")) {
                mms.setBodyFromSrc(parameters.getParameter("src", null));
                if (parameters.isParameter("srcMimeType")) {
                    mms.setBodyFromSrcMimeType(
                        parameters.getParameter("srcMimeType", null));
                }
            } else if (parameters.isParameter("body")) {
                mms.setBody(parameters.getParameter("body", null));
            }

            if (parameters.isParameter("attachments")) {
                String fileName[] = StringUtils.split(parameters.getParameter("attachments"));
                for (int i = 0; i < fileName.length; i++) {
                    String srcName = fileName[i];

                    if (srcName.indexOf(":") == -1) {
                        Object obj = request.get(srcName);
                        mms.addAttachment(obj);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("request-attachment: " + obj);
                        }
                    } else {
                        mms.addAttachmentURL(srcName,
                                             null,
                                             srcName.substring(srcName.lastIndexOf('/') + 1));
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("sitemap-attachment: " + srcName);
                        }
                    }
                }
            }

            mms.send();

            if (getLogger().isDebugEnabled()) {
                getLogger().debug("act stop");
            }
View Full Code Here

                   Parameters parameters)
    throws Exception {
        boolean success = false;
        Map status = null;

        MailSender mms = null;
        try {
            Request request = ObjectModelHelper.getRequest(objectModel);

            // FIXME Remove support of old smtphost parameter
            String smtpHost = parameters.getParameter("smtp-host", parameters.getParameter("smtphost", this.smtpHost));
            String smtpUser = parameters.getParameter("smtp-user", this.smtpUser);
            String smtpPassword = parameters.getParameter("smtp-password", this.smtpPassword);

            // Empty parameter means absent parameter
            if ("".equals(smtpHost)) {
                smtpHost = this.smtpHost;
            }
            if ("".equals(smtpUser)) {
                smtpUser = this.smtpUser;
            }
            if ("".equals(smtpPassword)) {
                smtpPassword = this.smtpPassword;
            }

            mms = (MailSender) this.manager.lookup(MailSender.ROLE);

            // Initialize non-default session if host or user specified.
            if (smtpHost != null || smtpUser != null) {
                mms.setSmtpHost(smtpHost, smtpUser, smtpPassword);
            }

            if (parameters.isParameter("from")) {
                mms.setFrom(parameters.getParameter("from", null));
            }
            if (parameters.isParameter("to")) {
                mms.setTo(parameters.getParameter("to", null));
            }
            if (parameters.isParameter("replyTo")) {
                mms.setReplyTo(parameters.getParameter("replyTo", null));
            }
            if (parameters.isParameter("cc")) {
                mms.setCc(parameters.getParameter("cc", null));
            }
            if (parameters.isParameter("bcc")) {
                mms.setBcc(parameters.getParameter("bcc", null));
            }
            if (parameters.isParameter("subject")) {
                mms.setSubject(parameters.getParameter("subject", null));
            }

            String bodyURL = parameters.getParameter("src", "");
            String body = parameters.getParameter("body", "");
            if (bodyURL.length() > 0) {
                String type = null;
                if (parameters.isParameter("srcMimeType")) {
                    type = parameters.getParameter("srcMimeType", null);
                }
                mms.setBodyURL(bodyURL, type);
            } else if (body.length() > 0) {
                String type = null;
                String charset = parameters.getParameter("charset", "");
                if (charset.length() > 0) {
                    type = "text/plain; charset=" + charset;
                }
                mms.setBody(body, type);
            }

            if (parameters.isParameter("attachments")) {
                String fileName[] = StringUtils.split(parameters.getParameter("attachments"));
                for (int i = 0; i < fileName.length; i++) {
                    String srcName = fileName[i];

                    if (srcName.indexOf(":") == -1) {
                        Object obj = request.get(srcName);
                        mms.addAttachment(obj);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("request-attachment: " + obj);
                        }
                    } else {
                        mms.addAttachmentURL(srcName);
                        if (getLogger().isDebugEnabled()) {
                            getLogger().debug("sitemap-attachment: " + srcName);
                        }
                    }
                }
            }

            mms.send();

            success = true;
            status = new HashMap(3);
            status.put(Sendmail.STATUS, "success");
View Full Code Here

TOP

Related Classes of org.apache.cocoon.mail.MailSender

Copyright © 2018 www.massapicom. 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.