Your SlideShare is downloading. ×
newsletter_Liferay.rtf
newsletter_Liferay.rtf
newsletter_Liferay.rtf
newsletter_Liferay.rtf
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

newsletter_Liferay.rtf

212

Published on

newsletter_Liferay.rtf

newsletter_Liferay.rtf

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
212
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. package com.liferay.portlet.newsletter.action;import java.util.ArrayList;import java.util.Arrays;import java.util.HashSet;import java.util.LinkedHashMap;import java.util.List;import java.util.Set;import com.liferay.portal.DuplicateGroupException;import com.liferay.portal.GroupFriendlyURLException;import com.liferay.portal.GroupNameException;import com.liferay.portal.NoSuchGroupException;import com.liferay.portal.RequiredGroupException;import com.liferay.portal.model.Group;import com.liferay.portal.model.Role;import com.liferay.portal.model.User;import com.liferay.portal.model.UserGroup;import com.liferay.portal.security.auth.PrincipalException;import com.liferay.portal.service.GroupLocalServiceUtil;import com.liferay.portal.service.GroupServiceUtil;import com.liferay.portal.service.RoleLocalServiceUtil;import com.liferay.portal.service.UserGroupLocalServiceUtil;import com.liferay.portal.service.UserLocalServiceUtil;import com.liferay.portal.service.persistence.RoleFinder;import com.liferay.portal.service.persistence.UserUtil;import com.liferay.portal.struts.PortletAction;import com.liferay.portal.util.Constants;import com.liferay.portal.util.PortalUtil;import com.liferay.portal.util.WebKeys;import com.liferay.portal.util.comparator.ContactLastNameComparator;import com.liferay.util.ParamUtil;import com.liferay.util.Validator;import com.liferay.util.dao.hibernate.QueryUtil;import com.liferay.util.mail.MailEngine;import com.liferay.util.servlet.SessionErrors;import javax.mail.internet.InternetAddress;import javax.portlet.ActionRequest;import javax.portlet.ActionResponse;import javax.portlet.PortletConfig;import javax.portlet.RenderRequest;import javax.portlet.RenderResponse;import org.apache.struts.action.ActionForm;import org.apache.struts.action.ActionForward;
  • 2. import org.apache.struts.action.ActionMapping;public class SendEmail extends PortletAction {public void processAction(ActionMapping mapping, ActionForm form, PortletConfig config,ActionRequest req, ActionResponse res)throws Exception {String[] userIds = req.getParameterValues("selected-users");String[] userGroupIds = req.getParameterValues("selected-usergroups");String[] groupIds = req.getParameterValues("selected-groups");String[] roleIds = req.getParameterValues("selected-roles");List addresses = new ArrayList();List tempList = new ArrayList();LinkedHashMap userParams = new LinkedHashMap();// Get all users in the selected groupsif (userGroupIds != null) {for (int i = 0; i < userGroupIds.length; i++) {UserGroup UG = UserGroupLocalServiceUtil.getUserGroup(userGroupIds);userParams.put("usersUserGroups", UG.getUserGroupId());tempList = UserLocalServiceUtil.search(PortalUtil.getCompanyId(req), null, null, null,null, true, userParams, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);for (int j = 0; j < tempList.size(); j++) {addresses.add(tempList.get(j));}}}userParams = new LinkedHashMap();// now communitiesif (groupIds != null) {for (int i = 0; i < groupIds.length; i++) {System.out.println(groupIds);Group group =GroupLocalServiceUtil.getUserGroup(PortalUtil.getCompanyId(req),groupIds);userParams.put("usersGroups", String.valueOf(group.getGroupId()));
  • 3. tempList = UserLocalServiceUtil.search(PortalUtil.getCompanyId(req), null, null, null,null, true, userParams, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);for (int j = 0; j < tempList.size(); j++) {addresses.add(tempList.get(j));}}}if (roleIds != null) {for (int i = 0; i < roleIds.length; i++) {Role role = RoleLocalServiceUtil.getRole(roleIds);userParams.put("usersRoles", role.getRoleId());tempList = UserLocalServiceUtil.search(PortalUtil.getCompanyId(req), null, null, null,null, true, userParams, true, QueryUtil.ALL_POS, QueryUtil.ALL_POS, null);for (int j = 0; j < tempList.size(); j++) {addresses.add(tempList.get(j));}}}if (userIds != null) {for (int i = 0; i < userIds.length; i++) {addresses.add(UserLocalServiceUtil.getUserById(userIds));}}//remove dupsSet set = new HashSet();set.addAll(addresses);if(set.size() < addresses.size()) {addresses.clear();addresses.addAll(set);}InternetAddress[] bcc = new InternetAddress[addresses.size()];for (int i = 0; i < addresses.size(); i++) {User communityUser = (User)addresses.get(i);bcc = new InternetAddress(communityUser.getEmailAddress(),communityUser.getEmailAddress());
  • 4. }User user = PortalUtil.getUser(req);InternetAddress from = new InternetAddress(user.getEmailAddress(),user.getFullName());String body = ParamUtil.getString(req, "body");String subject = ParamUtil.getString(req, "subject");MailEngine.send(from, null, null, bcc, subject, body);}public ActionForward render(ActionMapping mapping, ActionForm form, PortletConfig config,RenderRequest req, RenderResponse res)throws Exception {return mapping.findForward(getForward(req, "portlet.newsletter.send_email"));}} • Marcar como respuesta

×