Showing posts with label Mail. Show all posts
Showing posts with label Mail. Show all posts

Sending Mail in Liferay Using Templates(tmpl) Files


In the Previous blog we see how to we Configure mail in Liferay  and how to send a mail programmatically. When we send a mail we have to provide content in setBody() method either in plain text or in the HTML format. But what happen if we want to send a mail with dynamic content in body part and in proper HTML format.In this case we create templates with HTML tags and just call the tmpl files and replace the variables declared inside tmpl files with actual data.

So lets start this step by step:-


Step 1:-Create Liferay Project and Portlet
Create a Liferay Project in eclipse and then create a portlet in the Project.For theses you may refer Step 1 and Step 2 of my previous blog Here .

Step 2:-Create Template in the Project
Create a folder content inside src .After that inside this create a file with name exam.tmpl and paste this content .


Explanation:-
Here in this file we create a complete HTML structure and declare 3 variables NAME , RESULT ,PERCENTAGE and EXAM which we can set programmatically.




Step 3:-Use the Template 
Open your Controller ie java file and Paste this:-


Explanation:-
Inside sendMailUsingTemplate method we fetch the tmpl file using ContentUtil Class and then replace the 4 variables with our values.

Step 4:-Check Output 
As sendMailUsingTemplate method is called in doView method just deploy the portlet and add to page and check your inbox .You will receive a mail as:-



Project Structure:-







Hope this will Help....

You can Download Source code from  Sending Mail Using Templates.

Related Post:-

Sending Mail in Liferay Programmatically


In the Previous blog we see how to we Configure mail in Liferay.In this blog we will see how to send mail programmatically . Sending mail in Liferay is very simple we just need to use MailServiceUtil class that is provided by Liferay .Here we Consider 3 Scenario:-

So lets start :-


Scenario 1:-Send Mail With Plain Text
Create a method in your class as:-


Explanation:-

Here FromAddress should be same email address that is used in Configuration.

Output:-







Scenario 2:-Send Mail With HTML Text
Create a method in your class as:-


Explanation:-
Here we use two things:-

  • In mailMessage.setBody("") we use HTML tags.
  • And setHTMLFormat(true).

Output:-


Note:-  If you setHTMLFormat(false) than mail is sent successfully but the HTML tags are print as normal Text.

Scenario 3:-Send Mail With Attachment
Create a method in your class as:-


Explanation:-
Here we are using addition method addFileAttachment that take two arguments first is File object and second is Name that you want to given to attachment.

Output:-







Hope this will Help....

Related Post:-

Modify Email Notification Send by Liferay


In the Previous blog we see how to we Configure mail in Liferay.In this blog we will see how to modify/edit email notification send by Liferay. Liferay uses some tempelates to structure or design the mails body we just need to Change it.

So lets start this step by step:-


Step 1:-Change Template
Go to Admin->Control Panel->Portal Setting->Email Notification



Here you have 5 options:-

  • Sender
  • Account Created Notification
  • Email Verification Notification
  • Password Change Notification
  • Password Reset Notification.




Here i change the Sender Name from Test Test to Liferay Is Easy.
Now Click on Account Created Notification :-


Now Change this using WUSIWUG editor as:-



Step 2:- Check Output
Sign Out from admin and click sign in button .Now Click on Create Account and fill the form now check your mail you will get a mail as:-




The Red Color boxes represent our modification.





Hope this will Help....

Related Post:-

Mail Configuration in Liferay using Gmail


To we will discuss how to Configure Mail in Liferay so that when someone Create Account or forget Password a email notification is sent to his mail id. For Configuration mail in our Liferay we use Gmail .

So lets start this step by step:-


Step 1:-Configure Mail
Go to Admin->Control Panel->Server Administration->Mail






Provide the Configuration as Shown in the images just change the User Name with your Gmail Id and Click save.




Step 2:- Check Configuration
Sign Out from admin and click sign in button .Now Click on Create Account:-



Now Provide the fields as:-



and Click save. Now open your mail you will receive a mail as:-



In the next blog we will see how to customize this email notification that is sent by liferay.





Hope this will Help....

Related Post:-