Monday, 17 April 2017

Sending email to dynamic address using liferay "web-form-portlet"

I had a requirement to send the filled data on a web form portlet to custom email address. For example a user fills in data and want to receive the same on an email address he / she specifies during filling up the form.
  1.  Create a new field named as "Email" in web-from-portlet. 
  2. Modify the method in "WebFormPortlet.java" as follows
MailMessage mailMessage1 = new MailMessage();
            InternetAddress newToAddress = new InternetAddress(WebFormUtil.getEmailAddress(request, companyId,PortletPropsValues.ADMIN_EMAIL_FROM_ADDRESS),PortletPropsValues.ADMIN_EMAIL_FROM_NAME);
            mailMessage1.setHTMLFormat(true);
            mailMessage1.setFrom(newToAddress);
            InternetAddress toAddress = new InternetAddress(fieldsMap.get("Email"));
            mailMessage1.setTo(toAddress);
            mailMessage1.setBody("Thank you for your Interest");
            mailMessage1.setSubject(subject);
            MailServiceUtil.sendEmail(mailMessage1);


 

No comments:

Post a Comment