Package org.springframework.mail.javamail

Examples of org.springframework.mail.javamail.MimeMessageHelper


    @VisibleForTesting
    protected MimeMessagePreparator prepareFailMessage(final String userId, final String template, final String status) {
        return new MimeMessagePreparator() {
            public void prepare(MimeMessage mimeMessage) throws Exception {
                CbUser user = userDetailsService.getDetails(userId, UserFilterField.USERID);
                MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
                message.setFrom(msgFrom);
                message.setTo(user.getUsername());
                message.setSubject("Cloudbreak - stack installation");
                message.setText(getEmailBody(user.getGivenName(), status, "", template), true);
            }
        };
    }
View Full Code Here


            model.put(MESSAGE_SOURCE, messageSource);
            model.put(NO_ARGS, new Object[]{});
            String plainText = this.mergePlainTextTemplate(templateName, model);
            String htmlText = this.mergeHtmlTemplate(templateName, model);
            MimeMessage message = mailSender.createMimeMessage();
            MimeMessageHelper helper = new MimeMessageHelper(message, true);
            helper.setTo(to);
            helper.setFrom(from);
            helper.setSubject(subject);
            helper.setText(plainText, htmlText);
            mailSender.send(message);
        } catch (MailException | MessagingException e) {
            LOGGER.error("Mail sending failed", e);
            throw new MailingFailedException(e);
        }
View Full Code Here

                log.error("No DomainUserRequest found with ID: " + domainUserRequestId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject("Knappsack: Domain Access Request");

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (domainUserRequest != null) {
                    DomainEntityService domainEntityService = domainEntityServiceFactory.getDomainEntityService(domainUserRequest.getDomain().getDomainType());
                    Set<User> users = domainEntityService.getDomainRequestUsersForNotification(domainUserRequest.getDomain());

                    for (User user : users) {
                        Context ctx = new Context(locale);
                        ctx.setVariable("name", user.getFullName());
                        ctx.setVariable("request", domainUserRequest);

                        ctx.setVariable("url", request.generateURL("/manager"));
                        if(domainUserRequest.getDomain().getDomainType().equals(DomainType.ORGANIZATION)) {
                            applyBranding((Organization)domainUserRequest.getDomain(), ctx);
                        }

                        // Create the HTML body using Thymeleaf
                        final String htmlContent = this.templateEngine.process("email-domainUserAccessRequestTH", ctx);
                        message.setText(htmlContent, true /* isHtml */);
                        message.setTo(user.getEmail());

                        emailSent = sendMessage(mimeMessage);
                    }
                }
            } catch (MessagingException e) {
View Full Code Here

                log.error("No User found with ID: " + userId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {

                String organizationName = "";
                List<Organization> organizations = userService.getOrganizations(user, null);
                String subject = "Knappsack: Account Activation";
                Organization organization = null;
                if(organizations.size() == 1) {
                    organization = organizations.get(0);
                    organizationName = organizations.get(0).getName();
                    subject =  organizationName + ": Account Activation - Knappsack";
                }
                message.setSubject(subject);

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (user != null && !user.isActivated()) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("activationCode", user.getActivationCode());
                    ctx.setVariable("organizationName", organizationName);

                    String servletPath = "/activate/" + user.getActivationCode();
                    ctx.setVariable("url", request.generateURL(servletPath));
                    applyBranding(organization, ctx);

                    // Create the HTML body using Thymeleaf
                    final String htmlContent = this.templateEngine.process("email-accountActivationTH", ctx);
                    message.setText(htmlContent, true /* isHtml */);
                    message.setTo(user.getEmail());

                    emailSent = sendMessage(mimeMessage);
                }
            } catch (MessagingException e) {
                log.error(String.format("MessagingException sending an activation for: %s", user.getEmail()), e);
View Full Code Here

                log.error("No User found with ID: " + userId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                String organizationName = "";
                List<Organization> organizations = userService.getOrganizations(user, null);
                String subject = "Knappsack: Account Activation Success";
                Organization organization = null;
                if(organizations.size() == 1) {
                    organization = organizations.get(0);
                    organizationName = organizations.get(0).getName();
                    subject =  organizationName + ": Account Activation Success - Knappsack";
                }
                message.setSubject(subject);

                Locale locale = LocaleContextHolder.getLocale();

                message.setFrom(fromAddress);

                if (user != null && user.isActivated()) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("organizationName", organizationName);
                    String servletPath = "/";
                    ctx.setVariable("url", request.generateURL(servletPath));
                    applyBranding(organization, ctx);

                    final String htmlContent = this.templateEngine.process("email-accountActivationSuccessTH", ctx);
                    message.setText(htmlContent, true);
                    message.setTo(user.getEmail());

                    emailSent = sendMessage(mimeMessage);
                }
            } catch (MessagingException e) {
                log.error(String.format("MessagingException sending an activation for: %s", user.getEmail()), e);
View Full Code Here

            if (fromUserId != null) {
                fromUser = userService.get(fromUserId);
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");

            Locale locale = LocaleContextHolder.getLocale();

            Context ctx = new Context(locale);
            if (fromUser != null) {
                ctx.setVariable("adminName", fromUser.getFullName());
            }

            // Convert Invitation List to Map with email addresses being keys
            Map<String, List<Invitation>> emailMap = new HashMap<String, List<Invitation>>();
            for (Invitation invitation : invitations) {
                String key = StringUtils.trimAllWhitespace(invitation.getEmail()).toLowerCase();
                if (emailMap.get(key) == null) {
                    emailMap.put(key, new ArrayList<Invitation>());
                }
                emailMap.get(key).add(invitation);
            }

            Organization parentDomain = null;

            // Loop over each email address and send out a single invitation for each
            for (String emailAddress : emailMap.keySet()) {

                // Create Map separating domains for the email addresses invitations
                Map<String, Set<Invitation>> invitationsMap = new HashMap<String, Set<Invitation>>();
                for (Invitation invitation : emailMap.get(emailAddress)) {
                    if (DomainType.ORGANIZATION.equals(invitation.getDomain().getDomainType())) {
                        if (invitationsMap.get(DomainType.ORGANIZATION.name()) == null) {
                            invitationsMap.put(DomainType.ORGANIZATION.name(), new TreeSet<Invitation>(new InvitationDomainNameComparator()));
                        }
                        invitationsMap.get(DomainType.ORGANIZATION.name()).add(invitation);
                        parentDomain = (Organization) invitation.getDomain();
                    } else if (DomainType.GROUP.equals(invitation.getDomain().getDomainType())) {
                        if (invitationsMap.get(DomainType.GROUP.name()) == null) {
                            invitationsMap.put(DomainType.GROUP.name(), new TreeSet<Invitation>(new InvitationDomainNameComparator()));
                        }
                        invitationsMap.get(DomainType.GROUP.name()).add(invitation);
                        if(parentDomain == null) {
                            Group group = (Group) invitation.getDomain();
                            parentDomain = group.getOrganization();
                        }
                    }
                }

                ctx.setVariable("domainTypes", invitationsMap.keySet());
                ctx.setVariable("groupInvitations", invitationsMap.get(DomainType.GROUP.name()));
                String parentDomainName = parentDomain != null ? parentDomain.getName() : "";
                ctx.setVariable("parentDomainName", StringUtils.trimTrailingWhitespace(parentDomainName));

                User invitee = userService.getByEmail(emailAddress);
                if (invitee == null) {
                    ctx.setVariable("existingUser", false);
                    NameValuePair emailParam = new BasicNameValuePair("email", emailAddress);
                    ctx.setVariable("url", request.generateURL("/auth/register", emailParam));
                } else {
                    ctx.setVariable("existingUser", true);
                    ctx.setVariable("url", request.generateURL(""));
                }
                applyBranding(parentDomain, ctx);

                // Create the HTML body using Thymeleaf
                final String htmlContent = this.templateEngine.process("email-invitationTH", ctx);
                try {
                    message.setText(htmlContent, true /* isHtml */);
                    message.setTo(emailAddress);
                    message.setSubject(String.format("%s: Invitation to Knappsack", StringUtils.trimTrailingWhitespace(parentDomain.getName())));
                    message.setFrom(fromAddress);

                    if (sendMessage(mimeMessage)) {
                        for (Invitation invitation : emailMap.get(emailAddress)) {
                            invitationsSent.add(invitation.getId());
                        }
View Full Code Here

                log.error("No User found with ID: " + userId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject("Knappsack: Password Changed");

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                if (user != null) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("password", password);
                    ctx.setVariable("url", request.generateURL(""));

                    // Create the HTML body using Thymeleaf
                    final String htmlContent = this.templateEngine.process("email-passwordChangedTH", ctx);
                    message.setText(htmlContent, true /* isHtml */);
                    message.setTo(user.getEmail());

                    emailSent = sendMessage(mimeMessage);
                }
            } catch (MessagingException e) {
                log.error(String.format("MessagingException sending a password changed for: %s", user.getEmail()), e);
View Full Code Here

            if(application == null) {
                log.error("No application found for ApplicationVersion with ID: " + applicationVersionId);
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject("Knappsack: Application Publish Request");

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                Organization organization = null;
                try {
                    organization = applicationVersion.getApplication().getCategory().getOrganization();
                } catch (NullPointerException ex) {
                    log.error("NPE caused getting organization from application version", ex);
                }

                if (organization != null) {
                    List<UserDomain> userdomains = userDomainService.getAll(organization.getId(), UserRole.ROLE_ORG_ADMIN);

                    for (UserDomain userDomain : userdomains) {
                        Context ctx = new Context(locale);
                        ctx.setVariable("name", userDomain.getUser().getFullName());
                        ctx.setVariable("userName", userModel.getFullName());
                        ctx.setVariable("applicationName", applicationVersion.getApplication().getName());
                        ctx.setVariable("applicationVersion", applicationVersion.getVersionName());
                        ctx.setVariable("organizationName", organization.getName());
                        ctx.setVariable("url", request.generateURL("/manager"));

                        // Create the HTML body using Thymeleaf
                        final String htmlContent = this.templateEngine.process("email-applicationPublishRequestTH", ctx);
                        applyBranding(organization, ctx);
                        message.setText(htmlContent, true /* isHtml */);
                        message.setTo(userDomain.getUser().getEmail());

                        emailSent = sendMessage(mimeMessage);
                    }
                }
            } catch (MessagingException e) {
View Full Code Here

    public boolean sendDomainUserAccessConfirmationEmail(DomainUserRequestModel domainUserRequestModel) {
        boolean emailSent = false;
        WebRequest request = WebRequest.getInstance();
        if (sendEmail && domainUserRequestModel != null && domainUserRequestModel.getDomain() != null && domainUserRequestModel.getUser() != null && request != null) {
            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject(String.format("Knappsack: Domain Access Request %s", (Status.ACCEPTED.equals(domainUserRequestModel.getStatus()) ? "Accepted" : "Declined")));

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                User user = userService.get(domainUserRequestModel.getUser().getId());
                if (user != null) {
                    Context ctx = new Context(locale);
                    ctx.setVariable("name", user.getFullName());
                    ctx.setVariable("groupName", domainUserRequestModel.getDomain().getName());
                    ctx.setVariable("status", (Status.ACCEPTED.equals(domainUserRequestModel.getStatus()) ? true : false));
                    // Create the HTML body using Thymeleaf
                    final String htmlContent = this.templateEngine.process("email-domainUserAccessConfirmationTH", ctx);
                    message.setText(htmlContent, true /* isHtml */);
                    message.setTo(user.getEmail());

                    emailSent = sendMessage(mimeMessage);
                }
            } catch (MessagingException e) {
                log.error("MessagingException sending a group access confirmation:", e);
View Full Code Here

                log.error("No organization found with ID: " + organizationId);
                return true;
            }

            final MimeMessage mimeMessage = this.mailSender.createMimeMessage();
            final MimeMessageHelper message = new MimeMessageHelper(mimeMessage, "UTF-8");
            try {
                message.setSubject(String.format("Knappsack: %s Registration", organization.getName().trim()));

                Locale locale = LocaleContextHolder.getLocale();
                message.setFrom(fromAddress);

                Context ctx = new Context(locale);
                ctx.setVariable("organization", organization);

                boolean existingUser = false;
                if (userService.getByEmail(userModel.getEmail().trim()) != null) {
                    existingUser = true;
                }
                ctx.setVariable("existingUser", existingUser);
                ctx.setVariable("user", userModel);
                ctx.setVariable("url", request.generateURL(""));
                applyBranding(organization, ctx);

                // Create the HTML body using Thymeleaf
                final String htmlContent = this.templateEngine.process("email-organizationRegistrationTH", ctx);
                message.setText(htmlContent, true /* isHtml */);
                message.setTo(userModel.getEmail().trim());

                emailSent = sendMessage(mimeMessage);
            } catch (MessagingException e) {
                log.error(String.format("MessagingException sending a organization registration for: %s", organization.getName()), e);
            }
View Full Code Here

TOP

Related Classes of org.springframework.mail.javamail.MimeMessageHelper

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.