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

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

Introduction

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

Prototype

String ADMIN_EMAIL_FROM_ADDRESS

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

Click Source Link

Usage

From source file:com.liferay.portlet.flags.messaging.FlagsRequestMessageListener.java

License:Open Source License

@Override
protected void doReceive(Message message) throws Exception {
    FlagsRequest flagsRequest = (FlagsRequest) message.getPayload();

    // Service context

    ServiceContext serviceContext = flagsRequest.getServiceContext();

    // Company/* ww w  .j  a v a  2s  . com*/

    long companyId = serviceContext.getCompanyId();

    Company company = CompanyLocalServiceUtil.getCompany(serviceContext.getCompanyId());

    // Group

    Layout layout = LayoutLocalServiceUtil.getLayout(serviceContext.getPlid());

    Group group = layout.getGroup();

    String groupName = HtmlUtil.escape(group.getDescriptiveName());

    // Reporter user

    String reporterUserName = null;
    String reporterEmailAddress = null;

    User reporterUser = UserLocalServiceUtil.getUserById(serviceContext.getUserId());

    Locale locale = LocaleUtil.getDefault();

    if (reporterUser.isDefaultUser()) {
        reporterUserName = LanguageUtil.get(locale, "anonymous");
    } else {
        reporterUserName = reporterUser.getFullName();
        reporterEmailAddress = reporterUser.getEmailAddress();
    }

    // Reported user

    String reportedUserName = StringPool.BLANK;
    String reportedEmailAddress = StringPool.BLANK;
    String reportedURL = StringPool.BLANK;

    User reportedUser = UserLocalServiceUtil.getUserById(flagsRequest.getReportedUserId());

    if (reportedUser.isDefaultUser()) {
        reportedUserName = HtmlUtil.escape(group.getDescriptiveName());
    } else {
        reportedUserName = HtmlUtil.escape(reportedUser.getFullName());
        reportedEmailAddress = reportedUser.getEmailAddress();
        reportedURL = reportedUser.getDisplayURL(serviceContext.getPortalURL(), serviceContext.getPathMain());
    }

    // Content

    String contentType = ResourceActionsUtil.getModelResource(locale, flagsRequest.getClassName());

    // Reason

    String reason = LanguageUtil.get(locale, flagsRequest.getReason());

    // Email

    String fromName = PrefsPropsUtil.getStringFromNames(companyId, PropsKeys.FLAGS_EMAIL_FROM_NAME,
            PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String fromAddress = PrefsPropsUtil.getStringFromNames(companyId, PropsKeys.FLAGS_EMAIL_FROM_ADDRESS,
            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String subject = PrefsPropsUtil.getContent(companyId, PropsKeys.FLAGS_EMAIL_SUBJECT);
    String body = PrefsPropsUtil.getContent(companyId, PropsKeys.FLAGS_EMAIL_BODY);

    // Recipients

    List<User> recipients = getRecipients(companyId, serviceContext.getScopeGroupId());

    for (User recipient : recipients) {
        try {
            notify(company, groupName, reporterEmailAddress, reporterUserName, reportedEmailAddress,
                    reportedUserName, reportedURL, flagsRequest.getClassPK(), flagsRequest.getContentTitle(),
                    contentType, flagsRequest.getContentURL(), reason, fromName, fromAddress,
                    recipient.getFullName(), recipient.getEmailAddress(), subject, body, serviceContext);
        } catch (IOException ioe) {
            if (_log.isWarnEnabled()) {
                _log.warn(ioe);
            }
        }
    }
}

From source file:com.liferay.portlet.messageboards.service.impl.MBMessageLocalServiceImpl.java

License:Open Source License

protected void notifyDiscussionSubscribers(MBMessage message, ServiceContext serviceContext)
        throws SystemException {

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

        return;//from www .ja  v  a 2s.c o m
    }

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

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

    if (Validator.isNull(userName)) {
        userAddress = PortalUtil.getUserEmailAddress(message.getUserId());
        userName = PortalUtil.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.setContextAttributes("[$COMMENTS_BODY$]", message.getBody(true),
            "[$COMMENTS_USER_ADDRESS$]", userAddress, "[$COMMENTS_USER_NAME$]", userName, "[$CONTENT_URL$]",
            contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("mb_discussion", message.getCategoryId(), message.getMessageId());
    subscriptionSender.setScopeGroupId(message.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(subject);
    subscriptionSender.setUserId(message.getUserId());

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

    subscriptionSender.addPersistedSubscribers(className, classPK);

    subscriptionSender.flushNotificationsAsync();
}

From source file:com.liferay.socialnetworking.service.impl.WallEntryLocalServiceImpl.java

License:Open Source License

protected void sendEmail(WallEntry wallEntry, ThemeDisplay themeDisplay) throws Exception {

    long companyId = wallEntry.getCompanyId();

    String portalURL = PortalUtil.getPortalURL(themeDisplay);
    String layoutURL = PortalUtil.getLayoutURL(themeDisplay);

    String wallEntryURL = portalURL + layoutURL;

    Group group = GroupLocalServiceUtil.getGroup(wallEntry.getGroupId());

    User user = userLocalService.getUserById(group.getClassPK());
    User wallEntryUser = userLocalService.getUserById(wallEntry.getUserId());

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

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

    String subject = StringUtil.read(getClassLoader(),
            "com/liferay/socialnetworking/wall/dependencies/" + "wall_entry_added_subject.tmpl");
    String body = StringUtil.read(getClassLoader(),
            "com/liferay/socialnetworking/wall/dependencies/" + "wall_entry_added_body.tmpl");

    subject = StringUtil.replace(subject,
            new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]",
                    "[$WALL_ENTRY_URL$]", "[$WALL_ENTRY_USER_ADDRESS$]", "[$WALL_ENTRY_USER_NAME$]" },
            new String[] { fromAddress, fromName, toAddress, toName, wallEntryURL,
                    wallEntryUser.getEmailAddress(), wallEntryUser.getFullName() });

    body = StringUtil.replace(body,// w  w w.jav  a  2 s  .  c  o  m
            new String[] { "[$FROM_ADDRESS$]", "[$FROM_NAME$]", "[$TO_ADDRESS$]", "[$TO_NAME$]",
                    "[$WALL_ENTRY_URL$]", "[$WALL_ENTRY_USER_ADDRESS$]", "[$WALL_ENTRY_USER_NAME$]" },
            new String[] { fromAddress, fromName, toAddress, toName, wallEntryURL,
                    wallEntryUser.getEmailAddress(), wallEntryUser.getFullName() });

    InternetAddress from = new InternetAddress(fromAddress, fromName);

    InternetAddress to = new InternetAddress(toAddress, toName);

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

    MailServiceUtil.sendEmail(mailMessage);
}

From source file:com.sympo.portlet.messageboards.service.MentionUsersMessageServiceImpl.java

License:Open Source License

private MBMessage notifyMentions(MBMessage message, ServiceContext serviceContext)
        throws PortalException, SystemException {

    if (!message.isDiscussion()) {
        return message;
    }/*from  www  .  j a v a 2s  .  c  o  m*/

    ExpandoBridge expandoBridge = message.getExpandoBridge();

    String mentionedUsers = GetterUtil.getString(expandoBridge.getAttribute("mentionedUsers"));

    if (Validator.isNull(mentionedUsers)) {
        return message;
    }

    long companyId = message.getCompanyId();

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

    String mailUserAddress = PortalUtil.getUserEmailAddress(message.getUserId());
    String mailUserName = PortalUtil.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 mailSubject = ContentUtil.get(PropsUtil.get("discussion.mentioned.email.subject"));
    String mailBody = ContentUtil.get(PropsUtil.get("discussion.mentioned.email.body"));

    SubscriptionSender subscriptionSender = new SubscriptionSender();

    subscriptionSender.setBody(mailBody);
    subscriptionSender.setCompanyId(companyId);
    subscriptionSender.setContextAttribute("[$COMMENTS_BODY$]", message.getBody(true), false);
    subscriptionSender.setContextAttributes("[$COMMENTS_USER_ADDRESS$]", mailUserAddress,
            "[$COMMENTS_USER_NAME$]", mailUserName, "[$CONTENT_URL$]", contentURL);
    subscriptionSender.setFrom(fromAddress, fromName);
    subscriptionSender.setHtmlFormat(true);
    subscriptionSender.setMailId("mb_discussion", message.getCategoryId(), message.getMessageId());
    subscriptionSender.setScopeGroupId(message.getGroupId());
    subscriptionSender.setServiceContext(serviceContext);
    subscriptionSender.setSubject(mailSubject);
    subscriptionSender.setUserId(message.getUserId());

    String[] mentionedUsersArray = StringUtil.split(mentionedUsers);

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

        try {
            User mentionedUser = UserLocalServiceUtil.getUserByScreenName(companyId, screenName);

            subscriptionSender.addRuntimeSubscribers(mentionedUser.getEmailAddress(),
                    mentionedUser.getFullName());
        } catch (Exception e) {
        }
    }

    return message;
}

From source file:com.wcs.newsletter.util.SubscriberEmailSender.java

License:Open Source License

private void sendEmail(String email, String subject, String body, boolean sendHtml) throws Exception {
    InternetAddress rcpt = new InternetAddress(email);
    InternetAddress from = new InternetAddress(PrefsPropsUtil
            .getString(LiferayUtil.getThemeDisplay().getCompanyId(), PropsKeys.ADMIN_EMAIL_FROM_ADDRESS));

    MailMessage mailMessage = new MailMessage();
    mailMessage.setBody(body);/*from  w ww .  ja v a  2  s  .c o m*/
    mailMessage.setHTMLFormat(sendHtml);
    mailMessage.setFrom(from);
    mailMessage.setTo(rcpt);
    mailMessage.setSubject(subject);
    MailServiceUtil.sendEmail(mailMessage);
}

From source file:it.sysdata.base.service.impl.UserHelper_1_1ServiceImpl.java

License:Open Source License

@Override
@AccessControlled(guestAccessEnabled = true)
@JSONWebService(value = "send-new-password", method = "POST")
public User sendNewPassword(String emailAddress) throws PortalException, SystemException {

    ServiceContext serviceContext = ServiceContextThreadLocal.getServiceContext();

    String adminEmailFromName = PrefsPropsUtil.getString(serviceContext.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_NAME);
    String adminEmailFromAddress = PrefsPropsUtil.getString(serviceContext.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);

    String adminEmailPasswordResetSubject = PrefsPropsUtil.getContent(serviceContext.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_SUBJECT);
    String adminEmailPasswordResetBody = PrefsPropsUtil.getContent(serviceContext.getCompanyId(),
            PropsKeys.ADMIN_EMAIL_PASSWORD_RESET_BODY);

    UserLocalServiceUtil.sendPassword(serviceContext.getCompanyId(), emailAddress, adminEmailFromName,
            adminEmailFromAddress, adminEmailPasswordResetSubject, adminEmailPasswordResetBody, serviceContext);

    User user = UserLocalServiceUtil.getUserByEmailAddress(serviceContext.getCompanyId(), emailAddress);

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

From source file:it.sysdata.mqtt.service.impl.MqttLocalServiceImpl.java

License:Open Source License

private void _notityMail(String context, Throwable e) {

    try {/*from   w  ww .j av  a  2  s  .  c o m*/
        String errorMailTo = PrefsPropsUtil.getString(PortletPropsKeys.MQTT_ERRORS_SEND_MAIL_TO,
                PortletPropsValues.MQTT_ERRORS_SEND_MAIL_TO);

        if (Validator.isNotNull(errorMailTo)) {
            MailMessage mailMessage = new MailMessage();

            long companyId = PortalUtil.getDefaultCompanyId();

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

            mailMessage.setHTMLFormat(false);
            mailMessage.setTo(new InternetAddress(errorMailTo));
            mailMessage.setSubject(String.format("%s Mqtt connector error", PortalUtil.getComputerName()));
            mailMessage.setFrom(new InternetAddress(fromAddress));

            StringWriter sw = new StringWriter();
            PrintWriter pw = new PrintWriter(sw);
            e.printStackTrace(pw);

            mailMessage.setBody(String.format("context: %s\nerror: %s\n stacktrace:%s\n", context,
                    e.getMessage(), sw.toString()));

            MailServiceUtil.sendEmail(mailMessage);
        }
    } catch (Exception e1) {
        _log.error(e1);
    }
}

From source file:org.oep.cmon.portlet.taocongdan.mail.ChangePassRequestMail.java

License:Apache License

/**
 * Send mail/*from w ww.j  a  va  2 s  . c om*/
 * @throws IOException 
 */
public void send(ActionRequest request) throws IOException {
    // Get Mail template content
    URL resource = this.getClass().getClassLoader().getResource(MAIL_TEMPLATE);
    ThemeDisplay themeDisplay = (ThemeDisplay) request.getAttribute(WebKeys.THEME_DISPLAY);
    MailContext context = new MailContext();

    // Bind value to value place holder

    context.setProperty("citizen_name", this.fullName);
    context.setProperty("citizen_matKhau", this.matKhau);
    context.setProperty("citizen_email", this.email);
    context.setProperty("url", this.url);
    context.setProperty("uri", this.uri);
    try {
        // Create mail content
        String mailContent = MailTemplateUtil.getContent("change_pass_confirmation_mail.template",
                resource.openStream(), context);

        // Get the file from class package structure
        URL configResource = this.getClass().getClassLoader().getResource(MAIL_CONFIG);

        Properties props = new Properties();

        BufferedReader file = new BufferedReader(new InputStreamReader(configResource.openStream(), "utf-8"));
        props.load(file);

        String mailSubject = props.getProperty("MAIL_SUBJECT_ACCOUNT_CONFIRMATION");
        //String fromAddress = props.getProperty("FROM_ADDRESS");
        //String fromPerson = props.getProperty("FROM_PERSON");

        String fromAddress = PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
        String fromPerson = PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                PropsKeys.ADMIN_EMAIL_FROM_NAME);

        SendMailUtil.send(this.email, fromAddress, fromPerson, mailSubject, mailContent);

    } catch (Exception e) {

        // Sending mail failure should not stop the process flow

        // so this exception is swallowed and stack trace is printed out here

        e.printStackTrace();
    }
}

From source file:org.oep.cmon.user.portlet.business.EndorsementBs.java

License:Apache License

/**
 * This is function send email destroy registration
 * Version: 1.0/*  ww  w  . j  a va  2 s. co m*/
 *  
 * History: 
 *   DATE        AUTHOR      DESCRIPTION 
 *  ------------------------------------------------- 
 *  3-March-2013  Nam Dinh    Create new
 * @param fullname
 * @param email
 * @param password
 * @param url
 * @param actionRequest
 * @throws IOException
 */
public void sendEmailHuyDK(String fullName, String email, String url, ActionRequest actionRequest)
        throws IOException {
    // Get Mail template content
    URL resource = this.getClass().getClassLoader().getResource(MAIL_TEMPLATE_HUY);
    MailContext context = new MailContext();
    context.setProperty("citizen_name", fullName);
    context.setProperty("url", url);
    try {
        String mailContent = MailTemplateUtil.getContent("user_cancel_mail_template", resource.openStream(),
                context);
        URL configResource = this.getClass().getClassLoader().getResource(MAIL_CONFIG_HUY);
        Properties props = new Properties();
        BufferedReader file = new BufferedReader(new InputStreamReader(configResource.openStream(), "utf-8"));
        props.load(file);

        String mailSubject = props.getProperty("MAIL_SUBJECT_USER_CREATION");
        //String fromAddress = props.getProperty("FROM_ADDRESS");
        //String fromPerson = props.getProperty("FROM_PERSON");
        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
        String fromAddress = PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
        //String fromPerson = props.getProperty("FROM_PERSON");
        String fromPerson = PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                PropsKeys.ADMIN_EMAIL_FROM_NAME);

        SendMailUtil.send(email, fromAddress, fromPerson, mailSubject, mailContent);

    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.oep.cmon.user.portlet.mail.UserCreationMail.java

License:Apache License

/**
 * Send mail/*from w ww  .  ja  v  a  2 s  . c  o m*/
 * @throws IOException 
 */
public void send(ActionRequest actionRequest) throws IOException {
    // Get Mail template content
    URL resource = this.getClass().getClassLoader().getResource(MAIL_TEMPLATE);

    MailContext context = new MailContext();

    // Bind value to value place holder

    context.setProperty("citizen_name", this.fullName);

    context.setProperty("user_name", this.userName);

    context.setProperty("user_password", this.password);
    context.setProperty("url", this.url);

    try {
        // Create mail content
        String mailContent = MailTemplateUtil.getContent("user_creation_mail_template", resource.openStream(),
                context);

        // Get the file from class package structure
        URL configResource = this.getClass().getClassLoader().getResource(MAIL_CONFIG);

        Properties props = new Properties();

        BufferedReader file = new BufferedReader(new InputStreamReader(configResource.openStream(), "utf-8"));
        props.load(file);

        String mailSubject = props.getProperty("MAIL_SUBJECT_USER_CREATION");
        //String fromAddress = props.getProperty("FROM_ADDRESS");
        //String fromPerson = props.getProperty("FROM_PERSON");

        ThemeDisplay themeDisplay = (ThemeDisplay) actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
        String fromAddress = PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                PropsKeys.ADMIN_EMAIL_FROM_ADDRESS);
        //String fromPerson = props.getProperty("FROM_PERSON");
        String fromPerson = PrefsPropsUtil.getString(themeDisplay.getCompanyId(),
                PropsKeys.ADMIN_EMAIL_FROM_NAME);
        SendMailUtil.send(this.email, fromAddress, fromPerson, mailSubject, mailContent);

    } catch (Exception e) {

        // Sending mail failure should not stop the process flow

        // so this exception is swallowed and stack trace is printed out here

        e.printStackTrace();
    }
}