Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.test;
- import java.io.IOException;
- import javax.mail.internet.AddressException;
- import javax.mail.internet.InternetAddress;
- import javax.portlet.PortletException;
- import javax.portlet.RenderRequest;
- import javax.portlet.RenderResponse;
- import com.liferay.mail.service.MailServiceUtil;
- import com.liferay.portal.kernel.mail.MailMessage;
- import com.liferay.portal.kernel.util.StringUtil;
- import com.liferay.util.ContentUtil;
- import com.liferay.util.bridges.mvc.MVCPortlet;
- public class Demo extends MVCPortlet {
- @Override
- public void doView(RenderRequest renderRequest,RenderResponse renderResponse) throws IOException, PortletException {
- sendMailUsingTemplate();
- super.doView(renderRequest, renderResponse);
- }
- public void sendMailUsingTemplate() {
- InternetAddress fromAddress = null;
- InternetAddress toAddress = null;
- String body = ContentUtil.get("/content/exam.tmpl", true);
- body = StringUtil.replace(body, new String[] { "[$NAME$]","[$RESULT$]","[$PERCENTAGE$]","[$EXAM$]" }, new String[] { "Ravi", "CONGRATULATION" ,"80%" , "CCLP"});
- try {
- fromAddress = new InternetAddress("aa665845@gmail.com");
- toAddress = new InternetAddress("adit2787@gmail.com");
- MailMessage mailMessage = new MailMessage();
- mailMessage.setTo(toAddress);
- mailMessage.setFrom(fromAddress);
- mailMessage.setSubject("Send mail by Using Tempelate");
- mailMessage.setBody(body);
- mailMessage.setHTMLFormat(true);
- MailServiceUtil.sendEmail(mailMessage);
- System.out.println("Send mail by Using Tempelate");
- } catch (AddressException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement