Search in sources :

Example 1 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class UserFacadeImpl method resetPasswordRequest.

@Async
private void resetPasswordRequest(User user, String resetLink, MerchantStore store, Locale locale) throws Exception {
    try {
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(imageUtils.getContextPath(), store, messages, locale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", locale));
        templateTokens.put(EmailConstants.EMAIL_USER_FIRSTNAME, user.getFirstName());
        templateTokens.put(RESET_PASSWORD_LINK, resetLink);
        templateTokens.put(RESET_PASSWORD_TEXT, messages.getMessage("email.reset.password.text", new String[] { store.getStorename() }, locale));
        templateTokens.put(EmailConstants.LABEL_LINK_TITLE, messages.getMessage("email.link.reset.password.title", locale));
        templateTokens.put(EmailConstants.LABEL_LINK, messages.getMessage("email.link", locale));
        Email email = new Email();
        email.setFrom(store.getStorename());
        email.setFromEmail(store.getStoreEmailAddress());
        email.setSubject(messages.getMessage("email.link.reset.password.title", locale));
        email.setTo(user.getAdminEmail());
        email.setTemplateName(ACCOUNT_PASSWORD_RESET_TPL);
        email.setTemplateTokens(templateTokens);
        emailService.sendHtmlEmail(store, email);
    } catch (Exception e) {
        throw new Exception("Cannot send email to customer", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) ServiceException(com.salesmanager.core.business.exception.ServiceException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) OperationNotAllowedException(com.salesmanager.shop.store.api.exception.OperationNotAllowedException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) ConversionException(com.salesmanager.core.business.exception.ConversionException) Async(org.springframework.scheduling.annotation.Async)

Example 2 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class EmailTemplatesUtils method sendContactEmail.

@Async
public void sendContactEmail(ContactForm contact, MerchantStore merchantStore, Locale storeLocale, String contextPath) {
    /**
     * issue with putting that elsewhere *
     */
    LOGGER.info("Sending email to store owner");
    try {
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(contextPath, merchantStore, messages, storeLocale);
        templateTokens.put(EmailConstants.EMAIL_CONTACT_NAME, contact.getName());
        templateTokens.put(EmailConstants.EMAIL_CONTACT_EMAIL, contact.getEmail());
        templateTokens.put(EmailConstants.EMAIL_CONTACT_CONTENT, contact.getComment());
        String[] contactSubject = { contact.getSubject() };
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_CONTACT, messages.getMessage("email.contact", contactSubject, storeLocale));
        templateTokens.put(EmailConstants.EMAIL_CONTACT_NAME_LABEL, messages.getMessage("label.entity.name", storeLocale));
        templateTokens.put(EmailConstants.EMAIL_CONTACT_EMAIL_LABEL, messages.getMessage("label.generic.email", storeLocale));
        Email email = new Email();
        email.setFrom(contact.getName());
        // since shopizer sends email to store email, sender is store email
        email.setFromEmail(merchantStore.getStoreEmailAddress());
        email.setSubject(messages.getMessage("email.contact.title", storeLocale));
        // contact has to be delivered to store owner, receiver is store email
        email.setTo(merchantStore.getStoreEmailAddress());
        email.setTemplateName(EmailConstants.EMAIL_CONTACT_TMPL);
        email.setTemplateTokens(templateTokens);
        LOGGER.debug("Sending contact email");
        emailService.sendHtmlEmail(merchantStore, email);
    } catch (Exception e) {
        LOGGER.error("Error occured while sending contact email ", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) Async(org.springframework.scheduling.annotation.Async)

Example 3 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class EmailTemplatesUtils method sendRegistrationEmail.

/**
 * Sends an email to the customer after registration
 * @param request
 * @param customer
 * @param merchantStore
 * @param customerLocale
 */
@Async
public void sendRegistrationEmail(PersistableCustomer customer, MerchantStore merchantStore, Locale customerLocale, String contextPath) {
    /**
     * issue with putting that elsewhere *
     */
    LOGGER.info("Sending welcome email to customer");
    try {
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(contextPath, merchantStore, messages, customerLocale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", customerLocale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, customer.getBilling().getLastName());
        String[] greetingMessage = { merchantStore.getStorename(), filePathUtils.buildCustomerUri(merchantStore, contextPath), merchantStore.getStoreEmailAddress() };
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_GREETING, messages.getMessage("email.customer.greeting", greetingMessage, customerLocale));
        templateTokens.put(EmailConstants.EMAIL_USERNAME_LABEL, messages.getMessage("label.generic.username", customerLocale));
        templateTokens.put(EmailConstants.EMAIL_PASSWORD_LABEL, messages.getMessage("label.generic.password", customerLocale));
        templateTokens.put(EmailConstants.CUSTOMER_ACCESS_LABEL, messages.getMessage("label.customer.accessportal", customerLocale));
        templateTokens.put(EmailConstants.ACCESS_NOW_LABEL, messages.getMessage("label.customer.accessnow", customerLocale));
        templateTokens.put(EmailConstants.EMAIL_USER_NAME, customer.getUserName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_PASSWORD, customer.getPassword());
        // shop url
        String customerUrl = filePathUtils.buildStoreUri(merchantStore, contextPath);
        templateTokens.put(EmailConstants.CUSTOMER_ACCESS_URL, customerUrl);
        Email email = new Email();
        email.setFrom(merchantStore.getStorename());
        email.setFromEmail(merchantStore.getStoreEmailAddress());
        email.setSubject(messages.getMessage("email.newuser.title", customerLocale));
        email.setTo(customer.getEmailAddress());
        email.setTemplateName(EmailConstants.EMAIL_CUSTOMER_TPL);
        email.setTemplateTokens(templateTokens);
        LOGGER.debug("Sending email to {} on their  registered email id {} ", customer.getBilling().getFirstName(), customer.getEmailAddress());
        emailService.sendHtmlEmail(merchantStore, email);
    } catch (Exception e) {
        LOGGER.error("Error occured while sending welcome email ", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) Async(org.springframework.scheduling.annotation.Async)

Example 4 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method resetPasswordRequest.

@Async
private void resetPasswordRequest(Customer customer, String resetLink, MerchantStore store, Locale locale) throws Exception {
    try {
        // creation of a user, send an email
        String[] storeEmail = { store.getStoreEmailAddress() };
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(imageUtils.getContextPath(), store, messages, locale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", locale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
        templateTokens.put(RESET_PASSWORD_LINK, resetLink);
        templateTokens.put(RESET_PASSWORD_TEXT, messages.getMessage("email.reset.password.text", new String[] { store.getStorename() }, locale));
        templateTokens.put(EmailConstants.LABEL_LINK_TITLE, messages.getMessage("email.link.reset.password.title", locale));
        templateTokens.put(EmailConstants.LABEL_LINK, messages.getMessage("email.link", locale));
        templateTokens.put(EmailConstants.EMAIL_CONTACT_OWNER, messages.getMessage("email.contactowner", storeEmail, locale));
        Email email = new Email();
        email.setFrom(store.getStorename());
        email.setFromEmail(store.getStoreEmailAddress());
        email.setSubject(messages.getMessage("email.link.reset.password.title", locale));
        email.setTo(customer.getEmailAddress());
        email.setTemplateName(ACCOUNT_PASSWORD_RESET_TPL);
        email.setTemplateTokens(templateTokens);
        emailService.sendHtmlEmail(store, email);
    } catch (Exception e) {
        throw new Exception("Cannot send email to customer", e);
    }
}
Also used : Email(com.salesmanager.core.business.modules.email.Email) ServiceException(com.salesmanager.core.business.exception.ServiceException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) UnauthorizedException(com.salesmanager.shop.store.api.exception.UnauthorizedException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) GenericRuntimeException(com.salesmanager.shop.store.api.exception.GenericRuntimeException) Async(org.springframework.scheduling.annotation.Async)

Example 5 with Email

use of com.salesmanager.core.business.modules.email.Email in project shopizer by shopizer-ecommerce.

the class CustomerFacadeImpl method resetPassword.

@Override
public void resetPassword(Customer customer, MerchantStore store, Language language) {
    String password = new String(UUID.generateRandomBytes());
    String encodedPassword = passwordEncoder.encode(password);
    customer.setPassword(encodedPassword);
    try {
        customerService.saveOrUpdate(customer);
    } catch (Exception e) {
        throw new ServiceRuntimeException(e);
    }
    Locale locale = languageService.toLocale(language, store);
    try {
        // creation of a user, send an email
        String[] storeEmail = { store.getStoreEmailAddress() };
        Map<String, String> templateTokens = emailUtils.createEmailObjectsMap(imageUtils.getContextPath(), store, messages, locale);
        templateTokens.put(EmailConstants.LABEL_HI, messages.getMessage("label.generic.hi", locale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_FIRSTNAME, customer.getBilling().getFirstName());
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_LASTNAME, customer.getBilling().getLastName());
        templateTokens.put(EmailConstants.EMAIL_RESET_PASSWORD_TXT, messages.getMessage("email.customer.resetpassword.text", locale));
        templateTokens.put(EmailConstants.EMAIL_CONTACT_OWNER, messages.getMessage("email.contactowner", storeEmail, locale));
        templateTokens.put(EmailConstants.EMAIL_PASSWORD_LABEL, messages.getMessage("label.generic.password", locale));
        templateTokens.put(EmailConstants.EMAIL_CUSTOMER_PASSWORD, password);
        Email email = new Email();
        email.setFrom(store.getStorename());
        email.setFromEmail(store.getStoreEmailAddress());
        email.setSubject(messages.getMessage("label.generic.changepassword", locale));
        email.setTo(customer.getEmailAddress());
        email.setTemplateName(RESET_PASSWORD_TPL);
        email.setTemplateTokens(templateTokens);
        emailService.sendHtmlEmail(store, email);
    } catch (Exception e) {
        LOG.error("Cannot send email to customer", e);
    }
}
Also used : Locale(java.util.Locale) Email(com.salesmanager.core.business.modules.email.Email) ServiceException(com.salesmanager.core.business.exception.ServiceException) UserAlreadyExistException(com.salesmanager.shop.model.customer.UserAlreadyExistException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException) ConversionRuntimeException(com.salesmanager.shop.store.api.exception.ConversionRuntimeException) ResourceNotFoundException(com.salesmanager.shop.store.api.exception.ResourceNotFoundException) ConversionException(com.salesmanager.core.business.exception.ConversionException) ServiceRuntimeException(com.salesmanager.shop.store.api.exception.ServiceRuntimeException)

Aggregations

Email (com.salesmanager.core.business.modules.email.Email)10 Async (org.springframework.scheduling.annotation.Async)8 ServiceException (com.salesmanager.core.business.exception.ServiceException)3 ResourceNotFoundException (com.salesmanager.shop.store.api.exception.ResourceNotFoundException)3 ServiceRuntimeException (com.salesmanager.shop.store.api.exception.ServiceRuntimeException)3 ConversionException (com.salesmanager.core.business.exception.ConversionException)2 ConversionRuntimeException (com.salesmanager.shop.store.api.exception.ConversionRuntimeException)2 GenericRuntimeException (com.salesmanager.shop.store.api.exception.GenericRuntimeException)2 UnauthorizedException (com.salesmanager.shop.store.api.exception.UnauthorizedException)2 MerchantStore (com.salesmanager.core.model.merchant.MerchantStore)1 OrderTotal (com.salesmanager.core.model.order.OrderTotal)1 OrderProduct (com.salesmanager.core.model.order.orderproduct.OrderProduct)1 Country (com.salesmanager.core.model.reference.country.Country)1 Zone (com.salesmanager.core.model.reference.zone.Zone)1 UserAlreadyExistException (com.salesmanager.shop.model.customer.UserAlreadyExistException)1 OperationNotAllowedException (com.salesmanager.shop.store.api.exception.OperationNotAllowedException)1 ConfigurationTest (com.salesmanager.test.configuration.ConfigurationTest)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1