Blog

Latest technology news, trends and developers guide for business application. Visit this space for more tech updates.

Let’s work on your exciting new project together!

Send an Email from Liferay Portal

liferay, liferay portal

If you want to send an email from your liferay portal then its bit easy because liferay provide an Utility class called MailEngine.So we don’t have to play with direct JavaMail API.

In this article, we’ll use Gmail as SMTP

Below are the steps to send an email in Liferay.

  • Configure your SMTP provider, outgoing port, user id and password.
  • Login as super user in your liferay portal
  • Go to Control Panel
  • Click on Server Administration from server section
  • Click on Mail Tab
  • Fill out the SMTP fields here,
  • Set Outgoing SMTP Server (E.g. smtp.gmail.com)
  • Set Outgoing Port (E.g. 465)
  • Check the box of Use a Secure Network Connection if you want.
  • Set User Name and Password.
  • Press “Save” Button
  • You are done with SMTP configuration of outgoing mail sever
  • In your MVCPortlet or related class add the below peace of code to send an email.

MailMessage mailMessage = new MailMessage();
mailMessage.setHTMLFormat(true);
mailMessage.setBody("set body here");
mailMessage.setFrom(new InternetAddress("fromAddress","fromName"));
mailMessage.setSubject("set mail subject here");
mailMessage.setTo(new InternetAddress("set receiver email id here"));
mailEngine.send(mailMessage);

  • If you want to add attachment to your email or you want to add Cc you can use below send method of MailEngine class,
  • send(InternetAddress from, InternetAddress[] to, InternetAddress[] cc, InternetAddress[] bcc,
    String subject, String body, boolean html format, InternetAddress[] replyTo, String messageId,
    String inReplyTo, File[] attachments);

    I hope this tutorial will help you.. :)

    Embedding a Portlet in to a Web Content Portlet

    Create a portlet with any name, EX. "portlet-embedded". Write your code in portlet (view.jsp) to...

    Tips to Migrate from Liferay 6.0.x to Liferay 6.1

    Following are the important tips to Migrate from Liferay 6.0.x to Liferay 6.1: Unzip Liferay...

    Subscribe to our Newsletter Receive free e-guides, news, updates and more