Package org.eurekastreams.server.action.execution.email

Examples of org.eurekastreams.server.action.execution.email.NotificationEmailDTO


        Collection<UserActionRequest> results = sut.notify(NOTIFICATION_TYPE_ACTOR_REPLY, recipients,
                Collections.singletonMap(NotificationPropertyKeys.ACTOR, (Object) "WRONG!"), recipientIndex);
        mockery.assertIsSatisfied();

        NotificationEmailDTO request = assertGetSingleResult(results);
        assertNull(request.getReplyTo());
    }
View Full Code Here


     * {@inheritDoc}
     */
    @Override
    public Serializable execute(final ActionContext inActionContext) throws ExecutionException
    {
        NotificationEmailDTO request = (NotificationEmailDTO) inActionContext.getParams();
        try
        {
            MimeMessage message = emailer.createMessage();

            emailer.setSubject(message, request.getSubject());
            emailer.setTextBody(message, request.getTextBody());
            if (StringUtils.isNotBlank(request.getHtmlBody()))
            {
                emailer.setHtmlBody(message, request.getHtmlBody());
            }
            if (StringUtils.isNotBlank(request.getToRecipient()))
            {
                emailer.setTo(message, request.getToRecipient());
            }
            if (StringUtils.isNotBlank(request.getBccRecipients()))
            {
                emailer.setBcc(message, request.getBccRecipients());
            }
            if (StringUtils.isNotBlank(request.getReplyTo()))
            {
                emailer.setReplyTo(message, request.getReplyTo());
            }
            if (request.isHighPriority())
            {
                message.addHeader("Importance", "high");
                message.addHeader("X-Priority", "1");
            }

            emailer.sendMail(message);

            log.debug("Sent email for notification {}", request.getDescription());
        }
        catch (MessagingException ex)
        {
            String msg = "Failed to send email message for notification " + request.getDescription();
            log.error(msg, ex);
            throw new ExecutionException(msg, ex);
        }

        return null;
View Full Code Here

        }
        List<UserActionRequest> requests = new ArrayList<UserActionRequest>(emailCount);

        // -- prepare the email --

        NotificationEmailDTO email = new NotificationEmailDTO();

        // Note: The doubly-nested context is to prevent the code here and Velocity templates from updating
        // inProperties. The inner context uses inProperties as its backing store, so anything added to the context --
        // such as the values added here and any SET calls in templates -- would be added to inProperties, which we
        // don't want.
        Context velocityContext = new VelocityContext(new VelocityContext(inProperties, velocityGlobalContext));
        velocityContext.put("context", velocityContext);
        velocityContext.put("type", inType);
        if (addressesWithTokens.size() + addresses.size() == 1)
        {
            velocityContext.put("recipient", inRecipientIndex.get(inRecipients.iterator().next()));
        }

        // build the subject
        StringWriter writer = new StringWriter();
        velocityEngine.evaluate(velocityContext, writer, "EmailSubject-" + inType, template.getSubjectTemplate());
        email.setSubject(subjectPrefix + writer.toString());

        // set the priority
        email.setHighPriority(Boolean.TRUE.equals(inProperties.get(NotificationPropertyKeys.HIGH_PRIORITY)));

        // render the body

        String noReplyTextBody = null;
        String replyTextBody = null;
        String noReplyHtmlBody = null;
        String replyHtmlBody = null;

        // build the text body
        Template vt = velocityEngine.getTemplate(template.getTextBodyTemplateResourcePath());
        if (!addresses.isEmpty())
        {
            velocityContext.put("hasReplyAddress", false);
            writer.getBuffer().setLength(0);
            vt.merge(velocityContext, writer);
            noReplyTextBody = writer.toString();
        }
        if (!addressesWithTokens.isEmpty())
        {
            velocityContext.put("hasReplyAddress", true);
            writer.getBuffer().setLength(0);
            vt.merge(velocityContext, writer);
            replyTextBody = writer.toString();
        }

        // build the HTML body
        if (sendHtml)
        {
            final String htmlBodyTemplateResourcePath = template.getHtmlBodyTemplateResourcePath();
            if (htmlBodyTemplateResourcePath != null)
            {
                vt = velocityEngine.getTemplate(htmlBodyTemplateResourcePath);
                // HTML-escape all content inserted
                EventCartridge ec = new EventCartridge();
                ec.addEventHandler(new EscapeHtmlReference());
                ec.attachToContext(velocityContext);
                if (!addresses.isEmpty())
                {
                    velocityContext.put("hasReplyAddress", false);
                    writer.getBuffer().setLength(0);
                    vt.merge(velocityContext, writer);
                    noReplyHtmlBody = writer.toString();
                }
                if (!addressesWithTokens.isEmpty())
                {
                    velocityContext.put("hasReplyAddress", true);
                    writer.getBuffer().setLength(0);
                    vt.merge(velocityContext, writer);
                    replyHtmlBody = writer.toString();
                }
            }
        }

        // -- create requests to send emails --
        if (!addressesWithTokens.isEmpty())
        {
            email.setTextBody(replyTextBody);
            if (replyHtmlBody != null)
            {
                email.setHtmlBody(replyHtmlBody);
            }
            for (Entry<String, String> entry : addressesWithTokens.entrySet())
            {
                NotificationEmailDTO userEmail = email.clone();
                userEmail.setReplyTo(entry.getValue());
                String address = entry.getKey();
                userEmail.setToRecipient(address);
                // set the description (for logging / debugging)
                userEmail.setDescription(inType + " with token to " + address);

                requests.add(new UserActionRequest("sendEmailNotificationAction", null, userEmail));
            }
        }
        if (!addresses.isEmpty())
View Full Code Here

TOP

Related Classes of org.eurekastreams.server.action.execution.email.NotificationEmailDTO

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.