
« 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});
36936 Views