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.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"));

  • 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.. 🙂

Tell us Your
Big Idea!

  • =
  • This field is for validation purposes and should be left unchanged.

@2022 Solution Analysts Pvt Ltd. All Right Reserved