Send an Email from 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.setBody("set body here");
mailMessage.setSubject("set mail subject here");
mailMessage.setTo(new InternetAddress("set receiver email id here"));
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..