Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Mailing templates in Liferay

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 720
    Comment on it

    Hello Friends, The Below code will show How you can send the mail using the mailing template in liferay.


    <%@ taglib uri="" prefix="portlet" %>
    <%@ taglib uri="" prefix="aui" %>
    <portlet:defineObjects />
    <portlet:actionURL name="mailSenderTemplate" var="mailSenderTemplate"></portlet:actionURL>
    <aui:form name="mailSenderTemplate" id="mailSenderTemplate" action="<%= mailSenderTemplate.toString() %>">
        <aui:input type="text" name="toemail" fieldParam="toemail" />
        <aui:input type="textarea" name="subject" fieldParam="subject" />
        <aui:input type="submit" value="Submit" name="" />

    Then create folder named templates inside src folder of your portlet. After that create the sample.tmpl file inside templates folder.


    Hi [$NAME$],<br/><br/>
      [$DESC$]. <br/><br/>
    Thanx & Regards:-<br/>
    Manish Bohra<br/>

    package com.evon;
    import javax.mail.internet.InternetAddress;
    import javax.portlet.ActionRequest;
    import javax.portlet.ActionResponse;
    import javax.portlet.ProcessAction;
    import com.liferay.mail.service.MailServiceUtil;
    import com.liferay.portal.kernel.mail.MailMessage;
    import com.liferay.portal.kernel.util.ParamUtil;
    import com.liferay.portal.kernel.util.StringUtil;
    import com.liferay.portal.kernel.util.WebKeys;
    import com.liferay.portal.theme.ThemeDisplay;
    import com.liferay.util.ContentUtil;
    import com.liferay.util.bridges.mvc.MVCPortlet;
    public class MailSender extends MVCPortlet {
        @ProcessAction(name="mailSenderTemplate")  //sending  mail using template File
        public void mailSenderTemplate(ActionRequest actionRequest,ActionResponse actionResponse)
                        System.out.println("Inside mailSender template   :");
                        System.out.println("---->"+ParamUtil.getString(actionRequest, "toemail"));
                        System.out.println("---->"+ParamUtil.getString(actionRequest, "subject"));
                        //System.out.println("---->"+ParamUtil.getString(actionRequest, "tomail"));
                    try {
                        ThemeDisplay themeDisplay = (ThemeDisplay)actionRequest.getAttribute(WebKeys.THEME_DISPLAY);
                        InternetAddress toAddress = new InternetAddress(ParamUtil.getString(actionRequest, "toemail"));
                        InternetAddress fromAddress = new InternetAddress(themeDisplay.getCompany().getEmailAddress(), "DentalNoteBox");
                         String body = ContentUtil.get("/templates/sample.tmpl", true);  
                        // Here i have created a folder called content and also created file as sample.tmpl
                        String subject = ParamUtil.getString(actionRequest, "subject"); // email subject
                        body = StringUtil.replace(body, new String []{"[$NAME$]","[$DESC$]"}, new String []{"John","Hope you are doing good."}); // replacing the body with our content.
                        MailMessage mailMessage = new MailMessage();
                        MailServiceUtil.sendEmail(mailMessage); // Sending message
                    } catch (Exception e) {

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: