This wiki does not contain official documentation and is currently deprecated and read only. Please try reading the documentation on the Liferay Developer Network, the new site dedicated to Liferay documentation. DISCOVER Build your web site, collaborate with your colleagues, manage your content, and more. DEVELOP Build applications that run inside Liferay, extend the features provided out of the box with Liferay's APIs. DISTRIBUTE Let the world know about your app by publishing it in Liferay's marketplace. PARTICIPATE Become a part of Liferay's community, meet other Liferay users, and get involved in the open source project. « Back to Mail Integration
Mail Setup for External Portlets - JavaMail
(Redirected from Mail (JavaMail) Setup For External .WAR Portlets)
Table of Contents [-]
Introduction #
Liferay Portal provides the ability to configure mail server settings, so it would be redundant to configure these settings in each external portlet (.war).
In addition, the com.liferay.util.mail.MailEngine class provides convenience routines for sending email messages. In order to discover mail server settings, it performs a JNDI lookup for "java:comp/env/mail/MailSession" which is defined in a file determined by the servlet container / app server. In order for external portlets to be able to access the "mail/MailSession" resource, it must be available as a global JNDI lookup. For security purposes, Liferay does not make these settings globally availabe the out-of-the-box.
Ensuring Global JNDI Lookup #
For Tomcat:
- Move the "MailSession" <Resource> from
$CATALINA_HOME/conf/Catalina/localhost/ROOT.xml
to$CATALINA_HOME/conf/context.xml
For Geronimo:
- Using the console, un-deploy the
liferay-portal-tomcat
web application - Edit the mail server configuration settings of the
LiferayMailSession
<gbean>
within$GERONIMO_HOME/deploy/liferay-portal.war/WEB-INF/geronimo-web.xml
- Restart Geronimo, so that the portal will be re-deployed to the application server
For JBoss AS:
- Edit the settings in
$JBOSS_HOME/server/default/deploy/mail-service.xml
Java Source Code Example: #
import com.liferay.util.mail.MailEngine;
import com.liferay.util.mail.MailEngineException;
...
String attachment = "/home/mail/attachments/thankyou.doc";
InternetAddress fromInternetAddress = new InternetAddress(emailAddress);
InternetAddress[] toInternetAddresses = new InternetAddress[] {new InternetAddress(toEmailAddress)};
String subject = "My subject";
String body = "My message body";
MailEngine.send(fromInternetAddress, toInternetAddresses, null, null, subject, body, false, null, null, null, new File[] {_file}); 37271 Views