/** * Implement this method if you wish to be notified when the User has been Unbound from the * session. * * @param hsbe The HttpSessionBindingEvent. */ public void valueUnbound(HttpSessionBindingEvent hsbe) { try { java.util.Date now = new java.util.Date(); // System.out.println("*********** value unbound ********************: " + // now.toString()); if (this.hasLoggedIn()) { if (JetspeedResources.getBoolean("automatic.logout.save", false)) { JetspeedUserManagement.saveUser(this); } JetspeedAuthentication.logout(); } } catch (Exception e) { logger.error("TurbineUser.valueUnbound(): " + e.getMessage(), e); // To prevent messages being lost in case the logging system // goes away before sessions get unbound on servlet container // shutdown, print the stcktrace to the container's console. ByteArrayOutputStream ostr = new ByteArrayOutputStream(); e.printStackTrace(new PrintWriter(ostr, true)); String stackTrace = ostr.toString(); System.out.println(stackTrace); } }
/** * 送信するメールの内容を作成する. * * @return */ public static String createTaskMemberMsg( RunData rundata, String addr, EipTProjectTask task, EipTProject project) { VelocityContext context = new VelocityContext(); boolean enableAsp = JetspeedResources.getBoolean("aipo.asp", false); String CR = ALMailUtils.CR; context.put("user_email", addr); // (さんの申請は承認されました。など) StringBuffer message = new StringBuffer(""); message.append(CR); message .append(getl10nFormat("PROJECT_MAIL_TEXT", project.getProjectName(), task.getTaskName())) .append(CR); context.put("message", message); // サービス context.put("serviceAlias", ALOrgUtilsService.getAlias()); // サービス(Aipo)へのアクセス context.put("enableAsp", enableAsp); context.put("globalurl", ALMailUtils.getGlobalurl()); context.put("localurl", ALMailUtils.getLocalurl()); CustomLocalizationService locService = (CustomLocalizationService) ServiceUtil.getServiceByName(LocalizationService.SERVICE_NAME); String lang = locService.getLocale(rundata).getLanguage(); StringWriter writer = new StringWriter(); try { if (lang != null && lang.equals("ja")) { Template template = Velocity.getTemplate( "portlets/mail/" + lang + "/project-notification-mail.vm", "utf-8"); template.merge(context, writer); } else { Template template = Velocity.getTemplate("portlets/mail/project-notification-mail.vm", "utf-8"); template.merge(context, writer); } } catch (Exception e) { e.printStackTrace(); } writer.flush(); String ret = writer.getBuffer().toString(); return ret; }
/** アドレスブック・会社情報のファイル出力を取り扱うクラスです */ public class AddressBookCompanyXlsExportScreen extends ALXlsScreen { /** logger */ private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(AddressBookXlsExportScreen.class.getName()); /** アドレスブックファイルを一時保管するディレクトリの指定 */ public static final String FOLDER_TMP_FOR_ADDRESSBOOK_FILES = JetspeedResources.getString("aipo.tmp.addressbook.directory", ""); public static final String FILE_NAME = "addressbookcompany.xls"; /** ログインユーザーID */ private String userid; /** アクセス権限の機能名 */ private String aclPortletFeature = null; /** * 初期化処理を行います。 * * @param action * @param rundata * @param context */ @Override public void init(RunData rundata, Context context) throws ALPageNotFoundException, ALDBErrorException { String target_user_id = rundata.getParameters().getString("target_user_id" /* * AddressBookUtils. * TARGET_USER_ID */); userid = Integer.toString(ALEipUtils.getUserId(rundata)); // アクセス権 if ( // target_user_id == null || "".equals(target_user_id) // || userid.equals(target_user_id)) { aclPortletFeature = ALAccessControlConstants.POERTLET_FEATURE_ADDRESSBOOK_ADDRESS_OUTSIDE; } // else { // aclPortletFeature = // ALAccessControlConstants.POERTLET_FEATURE_TIMECARD_TIMECARD_OTHER; // } super.init(rundata, context); } @Override protected boolean createHSSFWorkbook(RunData rundata, Context context, HSSFWorkbook wb) { try { setupAddressBookSheet(rundata, context, wb); } catch (Exception e) { logger.error("AddressBookCompanyXlsExportScreen.createHSSFWorkbook", e); return false; } return true; } private void setupAddressBookSheet(RunData rundata, Context context, HSSFWorkbook wb) throws Exception { String sheet_name = "アドレスブック(会社情報)"; // ヘッダ部作成 String[] headers = {"会社名", "会社名(フリガナ)", "部署名", "郵便番号", "住所", "電話番号", "FAX", "URL"}; // 0:日本語,1:英数字 short[] cell_enc_types = { HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16, HSSFCell.ENCODING_UTF_16 }; HSSFSheet sheet = createHSSFSheet(wb, sheet_name, headers, cell_enc_types); int rowcount = 0; // スタイルの設定 HSSFCellStyle style_col = wb.createCellStyle(); style_col.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); style_col.setAlignment(HSSFCellStyle.ALIGN_JUSTIFY); AddressBookCompanySelectData listData = new AddressBookCompanySelectData(); listData.initField(); listData.setRowsNum(1000); listData.doSelectList(this, rundata, context); int page_num = listData.getPagesNum(); int current_page = 1; while (true) { int listsize = listData.getList().size(); AddressBookCompanyResultData rd; for (int j = 0; j < listsize; j++) { rd = (AddressBookCompanyResultData) listData.getList().get(j); String[] rows = { rd.getCompanyName().getValue(), rd.getCompanyNameKana().getValue(), rd.getPostName().getValue(), rd.getZipcode().getValue(), rd.getAddress().getValue(), rd.getTelephone().getValue(), rd.getFaxNumber().getValue(), rd.getUrl().getValue() }; rowcount = rowcount + 1; addRow(sheet.createRow(rowcount), cell_enc_types, rows); } current_page++; if (current_page > page_num) { break; } listData.setCurrentPage(current_page); listData.doSelectList(this, rundata, context); } int uid = ALEipUtils.getUserId(rundata); ALEventlogFactoryService.getInstance() .getEventlogHandler() .logXlsScreen( uid, "アドレスブック(会社情報)出力", 163 /* ALEventlogConstants.PORTLET_TYPE_ADDRESSBOOK_XLS_SCREEN */); } @Override protected String getFileName() { return FILE_NAME; } /** * アクセス権限チェック用メソッド。 アクセス権限の機能名を返します。 * * @return */ @Override public String getAclPortletFeature() { return aclPortletFeature; } }
public class ALEipConstants { public static final String ENTITY_ID = "entityid"; public static final String MODE = "mode"; public static final String MODE_UPDATE = "update"; public static final String MODE_DELETE = "delete"; public static final String MODE_MULTI_DELETE = "multi_delete"; public static final String MODE_INSERT = "insert"; public static final String MODE_FORM = "form"; public static final String MODE_NEW_FORM = "new_form"; public static final String MODE_EDIT_FORM = "edit_form"; public static final String MODE_LIST = "list"; public static final String MODE_DETAIL = "detail"; public static final String MODE_UPDATE_PASSWD = "update_passwd"; public static final String PORTLET_ID = "js_peid"; public static final String MESSAGE_LIST = "msgs"; public static final String ERROR_MESSAGE_LIST = "errmsgs"; public static final String RESULT = "result"; public static final String RESULT_LIST = "results"; public static final String POST_ENTITY_ID = "_entityid"; public static final String POST_DATE_YEAR = "_year"; public static final String POST_DATE_MONTH = "_month"; public static final String POST_DATE_DAY = "_day"; public static final String POST_DATE_HOUR = "_hour"; public static final String POST_DATE_MINUTE = "_minute"; public static final String LIST_START = "start"; public static final String LIST_SORT = "sort"; public static final String LIST_SORT_TYPE = "sorttype"; public static final String LIST_SORT_TYPE_ASC = "asc"; public static final String LIST_SORT_TYPE_DESC = "desc"; public static final String LIST_FILTER = "filter"; public static final String SEARCH = "search"; public static final String LIST_FILTER_TYPE = "filtertype"; public static final String LIST_INDEX = "index"; public static final String MYGROUP = "mygroup"; public static final String FACILITYGROUP = "facilitygroup"; public static final String UTILS = "utils"; /** 携帯電話の固有 ID のプレフィックス */ public static final String KEY_CELLULAR_UID = "cellularuid_"; /** 使用するデータベースサーバ名:PostgreSQL */ public static final String DB_NAME_POSTGRESQL = "postgresql"; /** デフォルトエンコーディング */ public static final String DEF_CONTENT_ENCODING = JetspeedResources.getString(JetspeedResources.CONTENT_ENCODING_KEY, "utf-8"); /** ユーザーの状態:削除 */ public static final String USER_STAT_DISABLED = "T"; /** ユーザーの状態:有効 */ public static final String USER_STAT_ENABLED = "F"; /** ユーザーの状態:無効 */ public static final String USER_STAT_NUTRAL = "N"; /** セキュリティID */ public static final String SECURE_ID = "secid"; }
/** Addressbookのユーティリティクラスです。 */ public class AddressBookUtils { /** logger */ private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(AddressBookUtils.class.getName()); /** アドレスブックファイルを一時保管するディレクトリの指定 */ public static final String FOLDER_TMP_FOR_ADDRESSBOOK_FILES = JetspeedResources.getString("aipo.tmp.addressbook.directory", ""); public static final String EMPTY_COMPANY_NAME = ""; public static final String ADDRESSBOOK_PORTLET_NAME = "AddressBook"; public static EipMAddressGroup getEipMAddressGroup(RunData rundata, Context context) { String groupid = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID); try { if (groupid == null || Integer.valueOf(groupid) == null) { // グループIDが空の場合 logger.debug("[AddressBook] Group ID..."); return null; } SelectQuery<EipMAddressGroup> query = Database.query(EipMAddressGroup.class); Expression exp1 = ExpressionFactory.matchDbExp( EipMAddressGroup.GROUP_ID_PK_COLUMN, Integer.valueOf(groupid)); query.setQualifier(exp1); Expression exp2 = ExpressionFactory.matchExp( EipMAddressGroup.OWNER_ID_PROPERTY, Integer.valueOf(ALEipUtils.getUserId(rundata))); query.andQualifier(exp2); List<EipMAddressGroup> groups = query.fetchList(); if (groups == null || groups.size() == 0) { // 指定したカテゴリIDのレコードが見つからない場合 logger.debug("[AddressBook] Not found Group ID..."); return null; } return groups.get(0); } catch (Exception ex) { logger.error("AddressBookUtils.getEipMAddressGroup", ex); return null; } } /** * 指定した取引先情報の取得 * * @param rundata * @param context * @return */ public static EipMAddressbookCompany getEipMAddressbookCompany(RunData rundata, Context context) { // セッションから指定された 取引先ID を取得 String companyid = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID); try { if (companyid == null || Integer.valueOf(companyid) == null) { logger.debug("[AddressBook] Company ID..."); return null; } SelectQuery<EipMAddressbookCompany> query = Database.query(EipMAddressbookCompany.class); Expression exp = ExpressionFactory.matchDbExp( EipMAddressbookCompany.COMPANY_ID_PK_COLUMN, Integer.valueOf(companyid)); query.setQualifier(exp); List<EipMAddressbookCompany> companys = query.fetchList(); if (companys == null || companys.size() == 0) { logger.debug("[AddressBook] Not found Company ID..."); return null; } return companys.get(0); } catch (Exception ex) { logger.error("AddressBookUtils.getEipMAddressbookCompany", ex); return null; } } /** * @param id * @return */ public static List<String> getMyGroupNames(RunData rundata, int addressid, int userid) { try { SelectQuery<EipTAddressbookGroupMap> query = Database.query(EipTAddressbookGroupMap.class); Expression exp1 = ExpressionFactory.matchExp( EipTAddressbookGroupMap.ADDRESS_ID_PROPERTY, Integer.valueOf(addressid)); query.setQualifier(exp1); Expression exp2 = ExpressionFactory.matchExp( EipTAddressbookGroupMap.EIP_TADDRESS_GROUP_PROPERTY + "." + EipMAddressGroup.OWNER_ID_PROPERTY, Integer.valueOf(userid)); query.andQualifier(exp2); List<EipTAddressbookGroupMap> groups = query.fetchList(); List<String> aList = new ArrayList<String>(); int size = groups.size(); for (int i = 0; i < size; i++) { aList.add(groups.get(i).getEipTAddressGroup().getGroupName()); } return aList; } catch (Exception ex) { logger.error("AddressBookUtils.getMyGroupNames", ex); } return null; } public static String getMyGroupNamesAsString(RunData rundata, int addressid, int userid) { List<String> aList = getMyGroupNames(rundata, addressid, userid); int group_size = aList.size(); StringBuffer groupNames = new StringBuffer(); for (int i = 0; i < group_size; i++) { groupNames.append(aList.get(i)).append("、"); } if (groupNames.length() == 0) { return ""; } else { return groupNames.substring(0, groupNames.length() - 1); } } /** * セッションで指定されたアドレスIDを持つアドレス情報を取得する。 * * @param rundata * @param context * @return */ public static EipMAddressbook getEipMAddressbook(RunData rundata, Context context) { // セッションから指定された アドレスID を取得 String addressid = ALEipUtils.getTemp(rundata, context, ALEipConstants.ENTITY_ID); try { if (addressid == null || Integer.valueOf(addressid) == null) { logger.debug("[AddressBook] Address ID..."); return null; } SelectQuery<EipMAddressbook> query = Database.query(EipMAddressbook.class); Expression exp11 = ExpressionFactory.matchDbExp( EipMAddressbook.ADDRESS_ID_PK_COLUMN, Integer.valueOf(addressid)); query.setQualifier(exp11); Expression exp21 = ExpressionFactory.matchExp(EipMAddressbook.PUBLIC_FLAG_PROPERTY, "T"); Expression exp22 = ExpressionFactory.matchExp( EipMAddressbook.OWNER_ID_PROPERTY, ALEipUtils.getUserId(rundata)); Expression exp23 = ExpressionFactory.matchExp(EipMAddressbook.PUBLIC_FLAG_PROPERTY, "F"); query.andQualifier(exp21.orExp(exp22.andExp(exp23))); List<EipMAddressbook> addresses = query.fetchList(); if (addresses == null || addresses.size() == 0) { logger.debug("[AddressBook] Not found Address ID..."); return null; } return addresses.get(0); } catch (Exception ex) { logger.error("AddressBookUtils.getEipMAddressbook", ex); return null; } } /** * その他の会社情報を取得する。 * * @param rundata * @param context * @return */ public static EipMAddressbookCompany getDummyEipMAddressbookCompany( RunData rundata, Context context) { // default company definition : company_id value is integer 1 return Database.get(EipMAddressbookCompany.class, Integer.valueOf(1)); } /** * 自分がオーナのグループを取得しID/Objectのマップを返却する。 * * @param rundata * @param context * @return */ public static Map<Integer, AddressBookGroup> getGroupMap(RunData rundata, Context context) { try { Map<Integer, AddressBookGroup> groupMap = new LinkedHashMap<Integer, AddressBookGroup>(); SelectQuery<EipMAddressGroup> query = Database.query(EipMAddressGroup.class); Expression exp = ExpressionFactory.matchExp( EipMAddressGroup.OWNER_ID_PROPERTY, Integer.valueOf(ALEipUtils.getUserId(rundata))); query.setQualifier(exp); List<EipMAddressGroup> list = query.fetchList(); int size = list.size(); for (int i = 0; i < size; i++) { EipMAddressGroup record = list.get(i); AddressBookGroup group = new AddressBookGroup(); group.initField(); group.setGroupId(record.getGroupId().intValue()); group.setGroupName(record.getGroupName()); groupMap.put(record.getGroupId(), group); } return groupMap; } catch (Exception ex) { logger.error("AddressBookUtils.getGroupMap", ex); return null; } } public static List<EipMAddressGroup> getGroups(int uid) { logger.debug("AddressbookUtils getGroups in"); try { SelectQuery<EipMAddressGroup> query = Database.query(EipMAddressGroup.class); Expression exp = ExpressionFactory.matchExp(EipMAddressGroup.OWNER_ID_PROPERTY, Integer.valueOf(uid)); query.setQualifier(exp); List<EipMAddressGroup> groups = query.fetchList(); if (groups == null || groups.size() == 0) { logger.debug("[AddressBook] Not found group ID..."); return null; } logger.debug("AddressbookUtils getGroups out"); return groups; } catch (Exception ex) { logger.error("AddressBookUtils.getGroups", ex); return null; } } public static List<ALStringField> getGroupMember(String gid) { List<ALStringField> resultList = new ArrayList<ALStringField>(); StringBuffer statement = new StringBuffer(); statement.append("SELECT "); statement.append(" B.last_name, B.first_name, "); statement.append(" C.company_name "); statement.append("FROM eip_t_addressbook_group_map as A "); statement.append("LEFT JOIN eip_m_addressbook as B "); statement.append(" on A.ADDRESS_ID = B.ADDRESS_ID "); statement.append("LEFT JOIN eip_m_addressbook_company AS C "); statement.append(" on B.COMPANY_ID = C.COMPANY_ID "); statement.append("WHERE A.GROUP_ID = #bind($gid) "); statement.append("ORDER BY C.company_name_kana, C.company_name, B.last_name_kana"); String query = statement.toString(); try { List<DataRow> list = Database.sql(EipMAddressbook.class, query) .param("gid", Integer.parseInt(gid)) .fetchListAsDataRow(); int recordNum = list.size(); DataRow dataRow; for (int i = 0; i < recordNum; i++) { dataRow = list.get(i); StringBuffer strBuf = new StringBuffer(); strBuf .append(Database.getFromDataRow(dataRow, EipMAddressbook.LAST_NAME_COLUMN)) .append(Database.getFromDataRow(dataRow, EipMAddressbook.FIRST_NAME_COLUMN)); String companyName = (String) Database.getFromDataRow(dataRow, EipMAddressbookCompany.COMPANY_NAME_COLUMN); if (companyName != null && companyName.trim().length() > 0) { strBuf.append(" (").append(companyName).append(")"); } ALStringField st = new ALStringField(strBuf.toString()); resultList.add(st); } } catch (Exception ex) { logger.error("AddressbookUtils.getGroupMember", ex); } return resultList; } /** * ユーザーの所属する部署の一覧を取得します。 * * @param uid ユーザーID * @return 所属する部署リスト */ public static List<AddressBookUserGroupLiteBean> getPostBeanList(int uid) { SelectQuery<TurbineUserGroupRole> query = Database.query(TurbineUserGroupRole.class); Expression exp1 = ExpressionFactory.matchExp( TurbineUserGroupRole.TURBINE_USER_PROPERTY, Integer.valueOf(uid)); Expression exp2 = ExpressionFactory.greaterExp( TurbineUserGroupRole.TURBINE_GROUP_PROPERTY, Integer.valueOf(3)); Expression exp3 = ExpressionFactory.matchExp( TurbineUserGroupRole.TURBINE_GROUP_PROPERTY + "." + TurbineGroup.OWNER_ID_PROPERTY, Integer.valueOf(1)); query.setQualifier(exp1); query.andQualifier(exp2); query.andQualifier(exp3); List<TurbineUserGroupRole> list = query.fetchList(); if (list == null || list.size() < 0) { return null; } List<AddressBookUserGroupLiteBean> resultList = new ArrayList<AddressBookUserGroupLiteBean>(); TurbineUserGroupRole ugr = null; TurbineGroup group = null; AddressBookUserGroupLiteBean bean = null; int size = list.size(); for (int i = 0; i < size; i++) { ugr = list.get(i); group = ugr.getTurbineGroup(); EipMPost post = group.getEipMPost(); bean = new AddressBookUserGroupLiteBean(); bean.initField(); bean.setGroupId(post.getPostId()); bean.setName(post.getPostName()); resultList.add(bean); } return resultList; } /** * 現在表示させているタブが「社外」であるかどうか調べます。 * * @param rundata * @param context * @return */ public static boolean isSyagai(RunData rundata, Context context) { String tabParam = rundata.getParameters().getString("tab"); String currentTab = ALEipUtils.getTemp(rundata, context, "tab"); if (tabParam == null) { if (currentTab == null || currentTab.trim().length() == 0 || "syagai".equals(currentTab)) { return true; } return false; } else { if ("syagai".equals(tabParam)) { return true; } return false; } } /** * TurbineUserクラスをもとに作った社内アドレスのResultDataを返します。 * * @param record * @param strLength 表示文字数 * @return */ public static AddressBookResultData getCorpResultData(TurbineUser record, int strLength) { AddressBookResultData rd = new AddressBookResultData(); rd.initField(); rd.setAddressId(record.getUserId().intValue()); rd.setName( ALCommonUtils.compressString( new StringBuffer() .append(record.getLastName()) .append(" ") .append(record.getFirstName()) .toString(), strLength)); if (record.getCompanyId().intValue() > 0) { rd.setCompanyName( ALCommonUtils.compressString( ALEipUtils.getCompanyName(record.getCompanyId().intValue()), strLength)); } rd.setPostList( compressString(AddressBookUtils.getPostBeanList(record.getUserId().intValue()), strLength)); if (record.getPositionId().intValue() > 0) { rd.setPositionName( ALCommonUtils.compressString( ALEipUtils.getPositionName(record.getPositionId()), strLength)); } rd.setEmail(ALCommonUtils.compressString(record.getEmail(), strLength)); rd.setTelephone(record.getOutTelephone()); rd.setCellularPhone(record.getCellularPhone()); rd.setCellularMail(record.getCellularMail()); rd.setInTelephone(record.getInTelephone()); return rd; } public static List<AddressBookUserGroupLiteBean> compressString( List<AddressBookUserGroupLiteBean> list, int length) { for (AddressBookUserGroupLiteBean bean : list) { bean.setName(ALCommonUtils.compressString(bean.getName(), length)); } return list; } public static Expression excludeDefaultCompanyCriteria() { Expression exp = ExpressionFactory.noMatchDbExp( EipMAddressbookCompany.COMPANY_ID_PK_COLUMN, Integer.valueOf(1)); return exp; } /** * 自分がオーナーのグループを取得します * * @param rundata * @return */ public static List<AddressBookGroupResultData> getMyGroups(RunData rundata) { List<AddressBookGroupResultData> res = new ArrayList<AddressBookGroupResultData>(); try { // 自分がオーナのグループ指定 SelectQuery<EipMAddressGroup> query = Database.query(EipMAddressGroup.class); Expression exp = ExpressionFactory.matchExp( EipMAddressGroup.OWNER_ID_PROPERTY, Integer.valueOf(ALEipUtils.getUserId(rundata))); query.orderAscending(EipMAddressGroup.GROUP_NAME_PROPERTY); query.setQualifier(exp); List<EipMAddressGroup> aList = query.fetchList(); for (EipMAddressGroup record : aList) { AddressBookGroupResultData rd = new AddressBookGroupResultData(); rd.initField(); rd.setGroupId(record.getGroupId().longValue()); rd.setGroupName(record.getGroupName()); res.add(rd); } } catch (Exception ex) { logger.error("AddressBookUtils.getMyGroups", ex); } return res; } }
/** * Sort the quotes. * * @param portlet The jsp-based portlet that is being built. * @param rundata The turbine rundata context for this request. */ public void doEmail(RunData rundata, Portlet portlet) { StringBuffer emailBody = new StringBuffer(); PortletEntry entry = (PortletEntry) Registry.getEntry(Registry.PORTLET, portlet.getName()); Iterator i = entry.getParameterNames(); while (i.hasNext()) { String name = (String) i.next(); Parameter param = entry.getParameter(name); if (param.isHidden() == false) { String title = param.getTitle(); String value = portlet.getPortletConfig().getInitParameter(name); value = value == null || value.length() == 0 ? "NOT PROVIDED" : value; emailBody.append(title); emailBody.append(" ===> "); emailBody.append(value); emailBody.append("\n\n"); } } String emailSmtp = JetspeedResources.getString(JetspeedResources.MAIL_SERVER_KEY); String emailFrom = JetspeedResources.getString("mail.support", "*****@*****.**"); String emailTo = rundata.getParameters().getString("emailTo", "*****@*****.**"); String emailAttachment = rundata.getRequest().getParameter("emailAttachment"); try { String emailText = emailBody.toString(); // Create the JavaMail session java.util.Properties properties = System.getProperties(); properties.put("mail.smtp.host", emailSmtp); Session emailSession = Session.getInstance(properties, null); // Construct the message MimeMessage message = new MimeMessage(emailSession); // Set the from address Address fromAddress = new InternetAddress(emailFrom); message.setFrom(fromAddress); // Parse and set the recipient addresses Address[] toAddresses = InternetAddress.parse(emailTo); message.setRecipients(Message.RecipientType.TO, toAddresses); // Set the subject and text message.setSubject("Jetspeed Questionnaire from " + rundata.getUser().getEmail()); message.setText(emailText); // Attach file with message if (emailAttachment != null) { File file = new File(emailAttachment); if (file.exists()) { // create and fill the first message part MimeBodyPart mbp1 = new MimeBodyPart(); mbp1.setText(emailText); // create the second message part MimeBodyPart mbp2 = new MimeBodyPart(); // attach the file to the message FileDataSource fds = new FileDataSource(emailAttachment); mbp2.setDataHandler(new DataHandler(fds)); mbp2.setFileName(fds.getName()); // create the Multipart and its parts to it Multipart mp = new MimeMultipart(); mp.addBodyPart(mbp1); mp.addBodyPart(mbp2); // add the Multipart to the message message.setContent(mp); } else { message.setText(emailBody.toString()); } } // send the message Transport.send(message); // Display confirmation rundata.getRequest().setAttribute("email", emailBody.toString()); String confirmTemplate = portlet .getPortletConfig() .getInitParameter("confirm.template", "JetspeedQuestionnaireConfirmation.jsp"); // this.setTemplate(rundata, portlet, confirmTemplate); setTemplate(rundata, confirmTemplate, true); rundata.setMessage("Email successfully sent"); } catch (Exception e) { logger.error("Exception", e); rundata.setMessage("Error sending email: " + e); } // buildNormalContext(portlet, rundata); }