Saturday, September 12, 2015

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:-

No comments:

Post a Comment

Total Pageviews

Like Us on Facebook

Number Of Unique Visitor

Free counters!