Advertisement
Guest User

Untitled

a guest
Sep 12th, 2015
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.57 KB | None | 0 0
  1. package com.test;
  2.  
  3. import java.io.IOException;
  4. import javax.mail.internet.AddressException;
  5. import javax.mail.internet.InternetAddress;
  6. import javax.portlet.PortletException;
  7. import javax.portlet.RenderRequest;
  8. import javax.portlet.RenderResponse;
  9. import com.liferay.mail.service.MailServiceUtil;
  10. import com.liferay.portal.kernel.mail.MailMessage;
  11. import com.liferay.portal.kernel.util.StringUtil;
  12. import com.liferay.util.ContentUtil;
  13. import com.liferay.util.bridges.mvc.MVCPortlet;
  14. public class Demo extends MVCPortlet {
  15.  
  16. @Override
  17. public void doView(RenderRequest renderRequest,RenderResponse renderResponse) throws IOException, PortletException {
  18. sendMailUsingTemplate();
  19. super.doView(renderRequest, renderResponse);
  20. }
  21.  
  22. public void sendMailUsingTemplate() {
  23. InternetAddress fromAddress = null;
  24. InternetAddress toAddress = null;
  25.  
  26. String body = ContentUtil.get("/content/exam.tmpl", true);
  27. body = StringUtil.replace(body, new String[] { "[$NAME$]","[$RESULT$]","[$PERCENTAGE$]","[$EXAM$]" }, new String[] { "Ravi", "CONGRATULATION" ,"80%" , "CCLP"});
  28. try {
  29. fromAddress = new InternetAddress("aa665845@gmail.com");
  30. toAddress = new InternetAddress("adit2787@gmail.com");
  31. MailMessage mailMessage = new MailMessage();
  32. mailMessage.setTo(toAddress);
  33. mailMessage.setFrom(fromAddress);
  34. mailMessage.setSubject("Send mail by Using Tempelate");
  35. mailMessage.setBody(body);
  36. mailMessage.setHTMLFormat(true);
  37. MailServiceUtil.sendEmail(mailMessage);
  38. System.out.println("Send mail by Using Tempelate");
  39. } catch (AddressException e) {
  40. e.printStackTrace();
  41. }
  42. }
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement