Liferay allows easy sending of user and email notifications through Liferay Objects by using notifications templates, without the need for coding. However, while this system works well for basic notifications triggered by actions like creating or updating objects, it doesn't support advanced scenarios like notifying multiple users based on specific conditions. Businesses need more control over who gets notified and when, ensuring the right people receive relevant alerts. This blog explores how to implement and customize these notifications effectively, ensuring timely communication for various business needs.
Prerequisites
Liferay Portal 7.4+
Objects
Creating an Object in Liferay
What is Object in Liferay?
Liferay object is a way of creating a custom entity without requiring custom coding or module deployment. You can learn more in our blog on .
To make a new object in Liferay, follow these steps:
Navigate to the Control Panel.
Navigate to Objects under the Object section.
Click Create New Object and add basic fields such as name, email, and phone number.
Once the object is configured, publish it.
Create Notifications
In Liferay, you can send notifications in two ways: User Notifications and Email Notifications.
After creating the object, follow these steps to creating notifications:
To configure these notifications, follow these steps:
Navigate to the Control Panel.
Go to Notifications and then select Template.
In the Template section, you can create and manage:
User Notifications
Email Notifications
Create User Notifications: -
We are creating user notifications for sending notifications to Liferay users.
To create a template using User Notifications, follow these steps:
Click on the Plus (+) Button and select User Notification.
Basic Info Section
Settings Section
Under Recipients in the Settings section, you can choose User, Role, or Definition Term.
User: If you choose User, you can select individual users from this site. The selected users will be notified when an object entry is created.
Role: If you choose Role, you can specify a role from this website. Notifications will be sent to users belonging to the role when an object entry is added.
Definition Term: In Definition term we can add dynamic values. In the sections below are general terms provided and any specific terms we need from object so we can get from Entity Dropdown.
Content Section
Definition Term: - In definitions terms there are general terms and Entity Dropdown. You can find your custom-created object in the Entity Dropdown. Simply select your object, and all the object fields will be available directly.
Once you’re done with all the template configurations, save the template.
Creating Object Actions to trigger User Notification.
Navigate to the object you created earlier.
Go to the Action tab in the object and create a new action.
Using the Action Builder, Select the Trigger when you are triggered and below Action select Notification and User Notification template also.
Checking User Notifications in Liferay
After completing the setup, add a new entry to the object. Once the new entry is added, navigate to the home page. Click on the User Profile button, and you can check the Notifications tab.
Email Notifications Template:
If you want to send email notifications to users using object actions, follow these steps:
Create New template Using Email Notifications.
Basic Info Section:
Settings Section:
Content Section:
Add the email subject.
In the editor, you can choose between rich text and free markup formats.
The content you add in this section will be used as the body of the email.
We have an attachment field in Object and want to send in email, you can directly select it and send it to the user.
In the Definition of Terms section, you can access dynamic fields from your object. This allows you to insert values like the user's name, email address, or any other object-related data into the email template dynamically.
Mail Configurations: -
Follow the steps below to set up the SMTP configuration:
Navigate to the: - Control Panel → Server Administration → Mail
In the Outgoing SMTP Server section, fill in the following properties:
Creating Object Actions to trigger Email Notification.
Navigate to the object you created earlier.
Go to the Action tab in the object and create a new action.
Using the Action Builder, Select the Trigger when you are triggered and below Action select Notification and Email Notification template also.
Now add a new Object Entry and it will send Email to the recipient Users.
Conclusion
Liferay 7.4 allows you to send user and email notifications without writing any custom code. By creating custom objects and using built-in notification templates, we can send user and email notifications. We can send notifications to specific users, roles, or dynamic recipients using object fields.