List of usage examples for com.liferay.portal.kernel.util PropsKeys MAIL_SESSION_MAIL_ADVANCED_PROPERTIES
String MAIL_SESSION_MAIL_ADVANCED_PROPERTIES
To view the source code for com.liferay.portal.kernel.util PropsKeys MAIL_SESSION_MAIL_ADVANCED_PROPERTIES.
Click Source Link
From source file:com.liferay.mail.service.impl.MailServiceImpl.java
License:Open Source License
public Session getSession() throws SystemException { if (_session != null) { return _session; }/*from w w w . ja v a 2 s . c o m*/ Session session = InfrastructureUtil.getMailSession(); if (!PrefsPropsUtil.getBoolean(PropsKeys.MAIL_SESSION_MAIL)) { _session = session; return _session; } String advancedPropertiesString = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES, PropsValues.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES); String pop3Host = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST, PropsValues.MAIL_SESSION_MAIL_POP3_HOST); String pop3Password = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD, PropsValues.MAIL_SESSION_MAIL_POP3_PASSWORD); int pop3Port = PrefsPropsUtil.getInteger(PropsKeys.MAIL_SESSION_MAIL_POP3_PORT, PropsValues.MAIL_SESSION_MAIL_POP3_PORT); String pop3User = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_POP3_USER, PropsValues.MAIL_SESSION_MAIL_POP3_USER); String smtpHost = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST, PropsValues.MAIL_SESSION_MAIL_SMTP_HOST); String smtpPassword = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD, PropsValues.MAIL_SESSION_MAIL_SMTP_PASSWORD); int smtpPort = PrefsPropsUtil.getInteger(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT, PropsValues.MAIL_SESSION_MAIL_SMTP_PORT); String smtpUser = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER, PropsValues.MAIL_SESSION_MAIL_SMTP_USER); String storeProtocol = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL, PropsValues.MAIL_SESSION_MAIL_STORE_PROTOCOL); String transportProtocol = PrefsPropsUtil.getString(PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL, PropsValues.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL); Properties properties = session.getProperties(); // Incoming if (!storeProtocol.equals(Account.PROTOCOL_POPS)) { storeProtocol = Account.PROTOCOL_POP; } properties.setProperty("mail.store.protocol", storeProtocol); String storePrefix = "mail." + storeProtocol + "."; properties.setProperty(storePrefix + "host", pop3Host); properties.setProperty(storePrefix + "password", pop3Password); properties.setProperty(storePrefix + "port", String.valueOf(pop3Port)); properties.setProperty(storePrefix + "user", pop3User); // Outgoing if (!transportProtocol.equals(Account.PROTOCOL_SMTPS)) { transportProtocol = Account.PROTOCOL_SMTP; } properties.setProperty("mail.transport.protocol", transportProtocol); String transportPrefix = "mail." + transportProtocol + "."; boolean smtpAuth = false; if (Validator.isNotNull(smtpPassword) || Validator.isNotNull(smtpUser)) { smtpAuth = true; } properties.setProperty(transportPrefix + "auth", String.valueOf(smtpAuth)); properties.setProperty(transportPrefix + "host", smtpHost); properties.setProperty(transportPrefix + "password", smtpPassword); properties.setProperty(transportPrefix + "port", String.valueOf(smtpPort)); properties.setProperty(transportPrefix + "user", smtpUser); // Advanced try { if (Validator.isNotNull(advancedPropertiesString)) { Properties advancedProperties = PropertiesUtil.load(advancedPropertiesString); Iterator<Map.Entry<Object, Object>> itr = advancedProperties.entrySet().iterator(); while (itr.hasNext()) { Map.Entry<Object, Object> entry = itr.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); properties.setProperty(key, value); } } } catch (IOException ioe) { if (_log.isWarnEnabled()) { _log.warn(ioe, ioe); } } _session = Session.getInstance(properties); return _session; }
From source file:com.liferay.portlet.admin.action.EditServerAction.java
License:Open Source License
protected void updateMail(ActionRequest actionRequest, PortletPreferences preferences) throws Exception { String advancedProperties = ParamUtil.getString(actionRequest, "advancedProperties"); String pop3Host = ParamUtil.getString(actionRequest, "pop3Host"); String pop3Password = ParamUtil.getString(actionRequest, "pop3Password"); int pop3Port = ParamUtil.getInteger(actionRequest, "pop3Port"); boolean pop3Secure = ParamUtil.getBoolean(actionRequest, "pop3Secure"); String pop3User = ParamUtil.getString(actionRequest, "pop3User"); String smtpHost = ParamUtil.getString(actionRequest, "smtpHost"); String smtpPassword = ParamUtil.getString(actionRequest, "smtpPassword"); int smtpPort = ParamUtil.getInteger(actionRequest, "smtpPort"); boolean smtpSecure = ParamUtil.getBoolean(actionRequest, "smtpSecure"); String smtpUser = ParamUtil.getString(actionRequest, "smtpUser"); String storeProtocol = Account.PROTOCOL_POP; if (pop3Secure) { storeProtocol = Account.PROTOCOL_POPS; }//from ww w . j a v a 2s. c o m String transportProtocol = Account.PROTOCOL_SMTP; if (smtpSecure) { transportProtocol = Account.PROTOCOL_SMTPS; } preferences.setValue(PropsKeys.MAIL_SESSION_MAIL, "true"); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES, advancedProperties); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST, pop3Host); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD, pop3Password); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_PORT, String.valueOf(pop3Port)); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_USER, pop3User); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST, smtpHost); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD, smtpPassword); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT, String.valueOf(smtpPort)); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER, smtpUser); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL, storeProtocol); preferences.setValue(PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL, transportProtocol); preferences.store(); MailServiceUtil.clearSession(); }
From source file:com.liferay.server.admin.web.internal.portlet.action.EditServerMVCActionCommand.java
License:Open Source License
protected void updateMail(ActionRequest actionRequest, PortletPreferences portletPreferences) throws Exception { String advancedProperties = ParamUtil.getString(actionRequest, "advancedProperties"); String pop3Host = ParamUtil.getString(actionRequest, "pop3Host"); String pop3Password = ParamUtil.getString(actionRequest, "pop3Password"); int pop3Port = ParamUtil.getInteger(actionRequest, "pop3Port"); boolean pop3Secure = ParamUtil.getBoolean(actionRequest, "pop3Secure"); String pop3User = ParamUtil.getString(actionRequest, "pop3User"); String smtpHost = ParamUtil.getString(actionRequest, "smtpHost"); String smtpPassword = ParamUtil.getString(actionRequest, "smtpPassword"); int smtpPort = ParamUtil.getInteger(actionRequest, "smtpPort"); boolean smtpSecure = ParamUtil.getBoolean(actionRequest, "smtpSecure"); String smtpUser = ParamUtil.getString(actionRequest, "smtpUser"); String storeProtocol = Account.PROTOCOL_POP; if (pop3Secure) { storeProtocol = Account.PROTOCOL_POPS; }//from ww w . j a va 2 s . c o m String transportProtocol = Account.PROTOCOL_SMTP; if (smtpSecure) { transportProtocol = Account.PROTOCOL_SMTPS; } portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL, "true"); portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_ADVANCED_PROPERTIES, advancedProperties); portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_HOST, pop3Host); if (!pop3Password.equals(Portal.TEMP_OBFUSCATION_VALUE)) { portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_PASSWORD, pop3Password); } portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_PORT, String.valueOf(pop3Port)); portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_POP3_USER, pop3User); portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST, smtpHost); if (!smtpPassword.equals(Portal.TEMP_OBFUSCATION_VALUE)) { portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD, smtpPassword); } portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT, String.valueOf(smtpPort)); portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER, smtpUser); portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_STORE_PROTOCOL, storeProtocol); portletPreferences.setValue(PropsKeys.MAIL_SESSION_MAIL_TRANSPORT_PROTOCOL, transportProtocol); portletPreferences.store(); _mailService.clearSession(); }