List of usage examples for com.liferay.portal.kernel.util PropsKeys MAIL_SESSION_MAIL_SMTP_HOST
String MAIL_SESSION_MAIL_SMTP_HOST
To view the source code for com.liferay.portal.kernel.util PropsKeys MAIL_SESSION_MAIL_SMTP_HOST.
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; }/*ww w. j ava2 s . c om*/ 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.newsletter.portlet.NewsletterPortlet.java
License:Open Source License
protected void configure(ActionRequest actionRequest, ActionResponse actionResponse) throws IOException, ReadOnlyException, ValidatorException { PortletProps.set(NewsletterConstants.ROWS_PER_PAGE, ParamUtil.getString(actionRequest, "rowsPerPage")); PortletProps.set(NewsletterConstants.SENDER_EMAIL, ParamUtil.getString(actionRequest, "senderEmail")); PortletProps.set(NewsletterConstants.SENDER_NAME, ParamUtil.getString(actionRequest, "senderName")); PortletProps.set(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST, ParamUtil.getString(actionRequest, "smtpHost")); PortletProps.set(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT, ParamUtil.getString(actionRequest, "smtpPort")); PortletProps.set(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER, ParamUtil.getString(actionRequest, "smtpUser")); PortletProps.set(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD, ParamUtil.getString(actionRequest, "smtpPassword")); }
From source file:com.liferay.newsletter.service.impl.NewsletterCampaignLocalServiceImpl.java
License:Open Source License
protected void sendEmail(long contactId, NewsletterCampaign campaign) throws PortalException, SystemException { String passwordString = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_PASSWORD); String userString = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_USER); String host = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST); String port = PortletProps.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_PORT); if (passwordString.isEmpty()) { passwordString = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST); }/*from w ww . j a v a 2 s . c o m*/ if (userString.isEmpty()) { userString = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST); } if (host.isEmpty()) { host = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST); } if (port.isEmpty()) { port = PropsUtil.get(PropsKeys.MAIL_SESSION_MAIL_SMTP_HOST); } Properties properties = new Properties(); properties.put(NewsletterConstants.MAIL_TRANSPORT_PROTOCOL, "smtp"); properties.put(NewsletterConstants.MAIL_SMTP_HOST, host); properties.put(NewsletterConstants.MAIL_SMTP_SOCKET_FACTORY_PORT, port); properties.put(NewsletterConstants.MAIL_SMTP_PORT, port); properties.put(NewsletterConstants.MAIL_SMTP_SOCKET_FACTORY_FALLBACK, "false"); properties.put(NewsletterConstants.MAIL_SMTP_STARTTLS_ENABLE, "true"); properties.put(NewsletterConstants.MAIL_SMTP_AUTH, "true"); MailAuthenticator mailAuthenticator = new MailAuthenticator(userString, passwordString); Session session = Session.getInstance(properties, mailAuthenticator); String senderEmail = campaign.getSenderEmail(); String emailSubject = campaign.getEmailSubject(); NewsletterContent content = campaign.getContent(); String senderName = campaign.getSenderName(); StringBundler sb = new StringBundler(10); sb.append(StringPool.QUOTE); sb.append(senderName); sb.append(StringPool.QUOTE); sb.append(StringPool.SPACE); sb.append(StringPool.LESS_THAN); sb.append(senderEmail); sb.append(StringPool.GREATER_THAN); String from = sb.toString(); NewsletterContact contact = newsletterContactLocalService.getContact(contactId); try { MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.setRecipient(Message.RecipientType.TO, new InternetAddress(contact.getEmail())); message.setSentDate(new Date()); message.setSubject(emailSubject); message.setContent(content.getContent(), "text/html"); Transport.send(message); } catch (Exception e) { throw new SendEmailException(e.getMessage()); } }
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 w w w.j a v a2s. c om 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.ja va2 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(); }