Example usage for com.liferay.portal.kernel.util PropsKeys ADMIN_EMAIL_FROM_NAME

List of usage examples for com.liferay.portal.kernel.util PropsKeys ADMIN_EMAIL_FROM_NAME

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.util PropsKeys ADMIN_EMAIL_FROM_NAME.

Prototype

String ADMIN_EMAIL_FROM_NAME

To view the source code for com.liferay.portal.kernel.util PropsKeys ADMIN_EMAIL_FROM_NAME.

Click Source Link

Usage

From source file:com.crm.subscriber.service.impl.SubscriberOrderLocalServiceImpl.java

License:Open Source License

public void emailTicket(long userId, long orderId, Date orderDate, String sendTo, String subject,
        String content) throws PortalException, SystemException {
    User user = userLocalService.getUser(userId);

    SubscriberOrder order = subscriberOrderPersistence.fetchByPrimaryKey(orderId);

    String endPoint = AppDomainLocalServiceUtil.getStringDomain("SERVICE", "resend");
    if (Validator.isNull(endPoint)) {
        endPoint = "http://183.91.14.218:8080/ChargingWS/services/charging";
    }// w ww .  j  a  v a  2  s  .  c  o  m
    System.out.println(endPoint);

    try {
        MerchantEntry merchant = MerchantEntryLocalServiceUtil.fetchMerchant(order.getMerchantId());
        MerchantAgent agent = MerchantAgentLocalServiceUtil.fetchAgent(order.getAgentId());
        ProductEntry product = ProductEntryLocalServiceUtil.fetchProduct(order.getProductId());

        if ((merchant != null) && (product != null)) {
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMddhhmmss");

            SMSRequest req = new SMSRequest();

            req.setIsdn(order.getIsdn());
            req.setCpId(order.getMerchantId());
            req.setAgentId(order.getAgentId());
            req.setDeliveryContent(order.getShippingTo());
            req.setPassword(agent.getPassword());
            req.setUsername(agent.getScreenName());
            req.setProduct(product.getAlias());
            req.setReqDate(dateFormat.format(new Date()));

            ChargingHttpBindingStub stub = new ChargingHttpBindingStub(new URL(endPoint), null);

            ServiceResponse res = stub.sendSMS(req);

            if (res != null) {
                if (!res.getStatus().equalsIgnoreCase("SV0000")) {
                    throw new PortalException("resend-error:" + res.getStatus());
                }
            }
        }

    } catch (PortalException e) {
        throw e;
    } catch (Exception e) {
        throw new PortalException(e.getMessage());
    }

    String fromAddress = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
    String fromName = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);

    if (Validator.isNull(fromAddress) || Validator.isNull(fromName)) {
        throw new PortalException("unknow-email-sender");
    }

    sendTo = Validator.isNull(sendTo) ? fromAddress : sendTo;
    subject = Validator.isNull(subject) ? "resend content to subscriber" : subject;

    if (Validator.isNull(content) && (order != null)) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm:sss");

        content = "User " + user.getScreenName() + " request resend content to subscriber " + order.getIsdn()
                + ".\r\n";
        content += "Request date: " + dateFormat.format(new Date()) + "\r\n";
        content += "Order date   : " + dateFormat.format(order.getOrderDate()) + "\r\n";
        content += "Product      : " + DisplayUtil.getProductTitle(order.getProductId()) + "\r\n";
        content += "Content      : " + order.getShippingTo() + "\r\n";
    }

    // build bulk receivers
    try {
        InternetAddress from = new InternetAddress(fromAddress, fromName);

        String[] toAddress = StringUtil.split(sendTo);

        MailMessage message = null;

        if (toAddress.length == 1) {
            InternetAddress to = new InternetAddress(toAddress[0]);

            message = new MailMessage(from, to, subject, content, true);
        } else {
            InternetAddress[] to = new InternetAddress[toAddress.length];

            for (int j = 0; j < toAddress.length; j++) {
                to[j] = new InternetAddress(toAddress[j]);
            }

            message = new MailMessage(from, subject, content, true);
        }

        message.setHTMLFormat(true);
        MailEngine.send(message);
    } catch (MailEngineException e) {
        throw new PortalException(e);
    } catch (Exception e) {
        throw new SystemException(e);
    }
}

From source file:com.liferay.blogs.settings.BlogsGroupServiceSettings.java

License:Open Source License

private static FallbackKeys _getFallbackKeys() {
    FallbackKeys fallbackKeys = new FallbackKeys();

    fallbackKeys.add("emailEntryAddedBody", PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_BODY);
    fallbackKeys.add("emailEntryAddedEnabled", PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_ENABLED);
    fallbackKeys.add("emailEntryAddedSubject", PropsKeys.BLOGS_EMAIL_ENTRY_ADDED_SUBJECT);
    fallbackKeys.add("emailEntryUpdatedBody", PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_BODY);
    fallbackKeys.add("emailEntryUpdatedEnabled", PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_ENABLED);
    fallbackKeys.add("emailEntryUpdatedSubject", PropsKeys.BLOGS_EMAIL_ENTRY_UPDATED_SUBJECT);
    fallbackKeys.add("emailFromAddress", PropsKeys.BLOGS_EMAIL_FROM_ADDRESS,
            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
    fallbackKeys.add("emailFromName", PropsKeys.BLOGS_EMAIL_FROM_NAME, PropsKeys.ADMIN_EMAIL_FROM_NAME);

    return fallbackKeys;
}

From source file:com.liferay.dynamic.data.lists.form.web.internal.notification.DDLFormEmailNotificationSender.java

License:Open Source License

protected String getEmailFromName(DDLRecordSet recordSet) throws PortalException {

    DDLRecordSetSettings recordSettings = recordSet.getSettingsModel();

    String defaultEmailFromName = PrefsPropsUtil.getString(recordSet.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_NAME);

    return GetterUtil.getString(recordSettings.emailFromName(), defaultEmailFromName);
}

From source file:com.liferay.dynamic.data.mapping.form.web.internal.notification.DDMFormEmailNotificationSender.java

License:Open Source License

protected String getEmailFromName(DDMFormInstance ddmFormInstance) throws PortalException {

    DDMFormInstanceSettings formInstancetings = ddmFormInstance.getSettingsModel();

    String defaultEmailFromName = PrefsPropsUtil.getString(ddmFormInstance.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_NAME);

    return GetterUtil.getString(formInstancetings.emailFromName(), defaultEmailFromName);
}

From source file:com.liferay.invitation.invite.members.service.impl.MemberRequestLocalServiceImpl.java

License:Open Source License

protected void sendEmail(String emailAddress, MemberRequest memberRequest, ServiceContext serviceContext)
        throws Exception {

    long companyId = memberRequest.getCompanyId();

    Group group = groupLocalService.getGroup(memberRequest.getGroupId());

    User user = userLocalService.getUser(memberRequest.getUserId());

    User receiverUser = null;//w  ww  .  j  a v  a  2s. c  o  m

    if (memberRequest.getReceiverUserId() > 0) {
        receiverUser = userLocalService.getUser(memberRequest.getReceiverUserId());
    }

    String fromName = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(companyId, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String toName = StringPool.BLANK;
    String toAddress = emailAddress;

    if (receiverUser != null) {
        toName = receiverUser.getFullName();
    }

    String subject = StringUtil.read(getClassLoader(),
            "com/liferay/invitation/invite/members/dependencies/subject.tmpl");

    String body = StringPool.BLANK;

    if (memberRequest.getReceiverUserId() > 0) {
        body = StringUtil.read(getClassLoader(),
                "com/liferay/invitation/invite/members/dependencies" + "/existing_user_body.tmpl");
    } else {
        body = StringUtil.read(getClassLoader(),
                "com/liferay/invitation/invite/members/dependencies" + "/new_user_body.tmpl");
    }

    subject = StringUtil.replace(subject,
            new String[] { "[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_USER$]" },
            new String[] { group.getDescriptiveName(serviceContext.getLocale()), user.getFullName() });

    body = StringUtil.replace(body,
            new String[] { "[$ADMIN_ADDRESS$]", "[$ADMIN_NAME$]", "[$MEMBER_REQUEST_CREATE_ACCOUNT_URL$]",
                    "[$MEMBER_REQUEST_GROUP$]", "[$MEMBER_REQUEST_LOGIN_URL$]", "[$MEMBER_REQUEST_USER$]" },
            new String[] { fromAddress, fromName, getCreateAccountURL(memberRequest, serviceContext),
                    group.getDescriptiveName(serviceContext.getLocale()),
                    getLoginURL(memberRequest, serviceContext), user.getFullName() });

    InternetAddress from = new InternetAddress(fromAddress, fromName);

    InternetAddress to = new InternetAddress(toAddress, toName);

    MailMessage mailMessage = new MailMessage(from, to, subject, body, true);

    mailService.sendEmail(mailMessage);
}

From source file:com.liferay.lms.service.impl.CourseServiceImpl.java

License:Open Source License

private void sendEmail(User user, Course course) {
    if (course.isWelcome() && user != null && course != null) {
        if (course.getWelcomeMsg() != null && course.getWelcomeMsg() != null
                && !StringPool.BLANK.equals(course.getWelcomeMsg())) {

            try {
                String emailTo = user.getEmailAddress();
                String nameTo = user.getFullName();
                InternetAddress to = new InternetAddress(emailTo, nameTo);

                String fromName = PrefsPropsUtil.getString(course.getCompanyId(),
                        PropsKeys.ADMIN_EMAIL_FROM_NAME);
                String fromAddress = PrefsPropsUtil.getString(course.getCompanyId(),
                        PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
                InternetAddress from = new InternetAddress(fromAddress, fromName);

                Company company = null;//  w w w.  j av  a 2s . c  o  m
                try {
                    company = CompanyLocalServiceUtil.getCompany(course.getCompanyId());
                } catch (PortalException e) {
                    if (log.isErrorEnabled())
                        log.error(e.getMessage());
                    if (log.isDebugEnabled())
                        e.printStackTrace();
                }

                if (company != null) {
                    String url = PortalUtil.getPortalURL(company.getVirtualHostname(), 80, false);
                    String urlcourse = url + "/web" + course.getFriendlyURL();

                    String subject = LanguageUtil.format(user.getLocale(), "welcome-subject",
                            new String[] { course.getTitle(user.getLocale()) });
                    String body = StringUtil.replace(course.getWelcomeMsg(),
                            new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$PAGE_URL$]",
                                    "[$PORTAL_URL$]", "[$TO_ADDRESS$]", "[$TO_NAME$]" },
                            new String[] { fromAddress, fromName, urlcourse, url, emailTo, nameTo });

                    MailMessage mailm = new MailMessage(from, to, subject, body, true);
                    MailServiceUtil.sendEmail(mailm);
                }

            } catch (UnsupportedEncodingException e) {
                if (log.isErrorEnabled())
                    log.error(e.getMessage());
                if (log.isDebugEnabled())
                    e.printStackTrace();
            } catch (SystemException e) {
                if (log.isErrorEnabled())
                    log.error(e.getMessage());
                if (log.isDebugEnabled())
                    e.printStackTrace();
            }
        }
    }
}

From source file:com.liferay.mentions.internal.util.DefaultMentionsNotifier.java

License:Open Source License

@Override
public void notify(long userId, long groupId, String title, String content, String className, long classPK,
        LocalizedValuesMap subjectLocalizedValuesMap, LocalizedValuesMap bodyLocalizedValuesMap,
        ServiceContext serviceContext) throws PortalException {

    String[] mentionedUsersScreenNames = getMentionedUsersScreenNames(userId, className, content);

    if (ArrayUtil.isEmpty(mentionedUsersScreenNames)) {
        return;/*from  ww  w .  j  a  v a  2 s  .  c  o m*/
    }

    User user = _userLocalService.getUser(userId);

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    String messageUserEmailAddress = _portal.getUserEmailAddress(userId);
    String messageUserName = _portal.getUserName(userId, StringPool.BLANK);

    String fromName = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setLocalizedBodyMap(LocalizationUtil.getMap(bodyLocalizedValuesMap));
    subscriptionSender.setClassName(className);
    subscriptionSender.setClassPK(classPK);
    subscriptionSender.setCompanyId(user.getCompanyId());
    subscriptionSender.setContextAttribute("[$CONTENT$]", content, false);
    subscriptionSender.setContextAttributes("[$USER_ADDRESS$]", messageUserEmailAddress, "[$USER_NAME$]",
            messageUserName, "[$CONTENT_URL$]", contentURL);
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(title);
    subscriptionSender.setEntryURL(contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setLocalizedContextAttributeWithFunction("[$ASSET_ENTRY_NAME$]",
            locale -> getAssetEntryName(className, locale));
    subscriptionSender.setMailId("mb_discussion", classPK);
    subscriptionSender.setNotificationType(MentionsConstants.NOTIFICATION_TYPE_MENTION);
    subscriptionSender.setPortletId(MentionsPortletKeys.MENTIONS);
    subscriptionSender.setScopeGroupId(groupId);
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setLocalizedSubjectMap(LocalizationUtil.getMap(subjectLocalizedValuesMap));

    for (String mentionedUserScreenName : mentionedUsersScreenNames) {
        User mentionedUser = _userLocalService.fetchUserByScreenName(user.getCompanyId(),
                mentionedUserScreenName);

        if (mentionedUser == null) {
            continue;
        }

        subscriptionSender.addRuntimeSubscribers(mentionedUser.getEmailAddress(), mentionedUser.getFullName());
    }

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.mentions.util.MentionsNotifier.java

License:Open Source License

public void notify(long userId, long groupId, String content, String className, long classPK, String subject,
        String body, ServiceContext serviceContext) throws PortalException {

    String[] mentionedUsersScreenNames = getMentionedUsersScreenNames(userId, content);

    if (ArrayUtil.isEmpty(mentionedUsersScreenNames)) {
        return;//from w  w  w.  j a  v a  2s . c om
    }

    User user = UserLocalServiceUtil.getUser(userId);

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    String messageUserEmailAddress = PortalUtil.getUserEmailAddress(userId);
    String messageUserName = PortalUtil.getUserName(userId, StringPool.BLANK);

    String fromName = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(user.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setClassName(className);
    subscriptionSender.setClassPK(classPK);
    subscriptionSender.setCompanyId(user.getCompanyId());
    subscriptionSender.setContextAttribute("[$CONTENT$]", content, false);
    subscriptionSender.setContextAttributes("[$ASSET_ENTRY_NAME$]",
            getAssetEntryName(className, serviceContext), "[$USER_ADDRESS$]", messageUserEmailAddress,
            "[USER_NAME$]", messageUserName, "[$CONTENT_URL$]", contentURL);
    subscriptionSender.setEntryTitle(content);
    subscriptionSender.setEntryURL(contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("mb_discussion", classPK);
    subscriptionSender.setNotificationType(MentionsConstants.NOTIFICATION_TYPE_MENTION);
    subscriptionSender.setPortletId(PortletKeys.MENTIONS);
    subscriptionSender.setScopeGroupId(groupId);
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(userId);

    for (int i = 0; i < mentionedUsersScreenNames.length; i++) {
        String mentionedUserScreenName = mentionedUsersScreenNames[i];

        User mentionedUser = UserLocalServiceUtil.fetchUserByScreenName(user.getCompanyId(),
                mentionedUserScreenName);

        if (mentionedUser == null) {
            continue;
        }

        subscriptionSender.addRuntimeSubscribers(mentionedUser.getEmailAddress(), mentionedUser.getFullName());
    }

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.message.boards.internal.service.SubscriptionMBMessageLocalServiceWrapper.java

License:Open Source License

protected void notifyDiscussionSubscribers(long userId, MBMessage message, ServiceContext serviceContext)
        throws PortalException {

    if (!PrefsPropsUtil.getBoolean(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_COMMENTS_ADDED_ENABLED)) {

        return;//from w  ww  . j av a  2 s .  co  m
    }

    MBDiscussion mbDiscussion = _mbDiscussionLocalService.getThreadDiscussion(message.getThreadId());

    String contentURL = (String) serviceContext.getAttribute("contentURL");

    contentURL = _http.addParameter(contentURL, serviceContext.getAttribute("namespace") + "messageId",
            message.getMessageId());

    String userAddress = StringPool.BLANK;
    String userName = (String) serviceContext.getAttribute("pingbackUserName");

    if (Validator.isNull(userName)) {
        userAddress = _portal.getUserEmailAddress(message.getUserId());
        userName = _portal.getUserName(message.getUserId(), StringPool.BLANK);
    }

    String fromName = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getString(message.getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String subject = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_SUBJECT);
    String body = PrefsPropsUtil.getContent(message.getCompanyId(), PropsKeys.DISCUSSION_EMAIL_BODY);

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(message.getCompanyId());
    subscriptionSender.setClassName(MBDiscussion.class.getName());
    subscriptionSender.setClassPK(mbDiscussion.getDiscussionId());
    subscriptionSender.setContextAttribute("[$COMMENTS_BODY$]", message.getBody(message.isFormatBBCode()),
            false);
    subscriptionSender.setContextAttributes("[$COMMENTS_USER_ADDRESS$]", userAddress, "[$COMMENTS_USER_NAME$]",
            userName, "[$CONTENT_URL$]", contentURL);
    subscriptionSender.setCurrentUserId(userId);
    subscriptionSender.setEntryTitle(message.getBody());
    subscriptionSender.setEntryURL(contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);

    Date modifiedDate = message.getModifiedDate();

    subscriptionSender.setMailId("mb_discussion", message.getCategoryId(), message.getMessageId(),
            modifiedDate.getTime());

    int notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_ADD_ENTRY;

    if (serviceContext.isCommandUpdate()) {
        notificationType = UserNotificationDefinition.NOTIFICATION_TYPE_UPDATE_ENTRY;
    }

    subscriptionSender.setNotificationType(notificationType);

    String portletId = PortletProviderUtil.getPortletId(Comment.class.getName(), PortletProvider.Action.VIEW);

    subscriptionSender.setPortletId(portletId);

    subscriptionSender.setScopeGroupId(message.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUniqueMailId(false);

    String className = (String) serviceContext.getAttribute("className");
    long classPK = ParamUtil.getLong(serviceContext, "classPK");

    subscriptionSender.addPersistedSubscribers(className, classPK);

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.portlet.announcements.service.impl.AnnouncementsEntryLocalServiceImpl.java

License:Open Source License

protected void notifyUsers(AnnouncementsEntry entry) throws PortalException, SystemException {

    Company company = companyPersistence.findByPrimaryKey(entry.getCompanyId());

    String className = entry.getClassName();
    long classPK = entry.getClassPK();

    String fromName = PrefsPropsUtil.getStringFromNames(entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_NAME, PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getStringFromNames(entry.getCompanyId(),
            PropsKeys.ANNOUNCEMENTS_EMAIL_FROM_ADDRESS, PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String toName = PropsValues.ANNOUNCEMENTS_EMAIL_TO_NAME;
    String toAddress = PropsValues.ANNOUNCEMENTS_EMAIL_TO_ADDRESS;

    LinkedHashMap<String, Object> params = new LinkedHashMap<String, Object>();

    params.put("announcementsDeliveryEmailOrSms", entry.getType());

    if (classPK > 0) {
        if (className.equals(Group.class.getName())) {
            Group group = groupPersistence.findByPrimaryKey(classPK);

            toName = group.getName();//from   w w  w.  j  ava 2 s. c o m

            params.put("usersGroups", classPK);
        } else if (className.equals(Organization.class.getName())) {
            Organization organization = organizationPersistence.findByPrimaryKey(classPK);

            toName = organization.getName();

            params.put("usersOrgs", classPK);
        } else if (className.equals(Role.class.getName())) {
            Role role = rolePersistence.findByPrimaryKey(classPK);

            toName = role.getName();

            params.put("usersRoles", classPK);
        } else if (className.equals(UserGroup.class.getName())) {
            UserGroup userGroup = userGroupPersistence.findByPrimaryKey(classPK);

            toName = userGroup.getName();

            params.put("usersUserGroups", classPK);
        }
    }

    List<User> users = null;

    if (className.equals(User.class.getName())) {
        User user = userPersistence.findByPrimaryKey(classPK);

        toName = user.getFullName();
        toAddress = user.getEmailAddress();

        users = new ArrayList<User>();

        if (Validator.isNotNull(toAddress)) {
            users.add(user);
        }
    } else {
        users = userLocalService.search(company.getCompanyId(), null, WorkflowConstants.STATUS_APPROVED, params,
                QueryUtil.ALL_POS, QueryUtil.ALL_POS, (OrderByComparator) null);
    }

    if (_log.isDebugEnabled()) {
        _log.debug("Notifying " + users.size() + " users");
    }

    boolean notifyUsers = false;

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    for (User user : users) {
        AnnouncementsDelivery announcementsDelivery = announcementsDeliveryLocalService
                .getUserDelivery(user.getUserId(), entry.getType());

        if (announcementsDelivery.isEmail()) {
            subscriptionSender.addRuntimeSubscribers(user.getEmailAddress(), user.getFullName());

            notifyUsers = true;
        }

        if (announcementsDelivery.isSms()) {
            String smsSn = user.getContact().getSmsSn();

            subscriptionSender.addRuntimeSubscribers(smsSn, user.getFullName());

            notifyUsers = true;
        }
    }

    if (!notifyUsers) {
        return;
    }

    String subject = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_SUBJECT);
    String body = ContentUtil.get(PropsValues.ANNOUNCEMENTS_EMAIL_BODY);

    subscriptionSender.setBody(body);
    subscriptionSender.setCompanyId(entry.getCompanyId());
    subscriptionSender.setContextAttributes("[$ENTRY_CONTENT$]", entry.getContent(), "[$ENTRY_ID$]",
            entry.getEntryId(), "[$ENTRY_TITLE$]", entry.getTitle(), "[$ENTRY_TYPE$]",
            LanguageUtil.get(company.getLocale(), entry.getType()), "[$ENTRY_URL$]", entry.getUrl(),
            "[$PORTLET_NAME$]",
            LanguageUtil.get(company.getLocale(), (entry.isAlert() ? "alert" : "announcement")));
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("announcements_entry", entry.getEntryId());
    subscriptionSender.setPortletId(PortletKeys.ANNOUNCEMENTS);
    subscriptionSender.setScopeGroupId(entry.getGroupId());
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(entry.getUserId());

    subscriptionSender.addRuntimeSubscribers(toAddress, toName);

    subscriptionSender.flushNotificationsAsync();
}