portlet.xml
<?xml
version="1.0"?>
<portlet-app
xmlns="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd
http://java.sun.com/xml/ns/portlet/portlet-app_2_0.xsd"
version="2.0">
<portlet>
<portlet-name>sendingmail</portlet-name>
<display-name>Sendingmail</display-name>
<portlet-class>org.springframework.web.portlet.DispatcherPortlet</portlet-class>
<expiration-cache>0</expiration-cache>
<supports>
<mime-type>text/html</mime-type>
</supports>
<portlet-info>
<title>Sendingmail</title>
<short-title>Sendingmail</short-title>
<keywords>Sendingmail</keywords>
</portlet-info>
<security-role-ref>
<role-name>administrator</role-name>
</security-role-ref>
<security-role-ref>
<role-name>guest</role-name>
</security-role-ref>
<security-role-ref>
<role-name>power-user</role-name>
</security-role-ref>
<security-role-ref>
<role-name>user</role-name>
</security-role-ref>
</portlet>
</portlet-app>
Sendingmail-portlet.xml
<?xml
version="1.0"
encoding="UTF-8"?>
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd">
<context:component-scan
base-package="com.java.spring"
/>
<bean
id="mail"
class="com.java.spring.SendEmailAttachController"
/>
<bean
id="portletModeHandlerMapping"
class="org.springframework.web.portlet.handler.PortletModeHandlerMapping">
<property
name="portletModeMap">
<map>
<entry
key="view">
<ref
bean="mail"
/>
</entry>
</map>
</property>
</bean>
<bean
id="mailSender"
class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property
name="host"
value="smtp.gmail.com"
/>
<property
name="port"
value="587"
/>
<property
name="username"
value="mail id"
/>
<property
name="password"
value="password"
/>
<property
name="javaMailProperties">
<props>
<prop
key="mail.transport.protocol">smtp</prop>
<prop
key="mail.smtp.auth">true</prop>
<prop
key="mail.smtp.starttls.enable">true</prop>
</props>
</property>
</bean>
<bean
id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property
name="prefix"
value="/"
/>
<property
name="suffix"
value=".jsp"
/>
</bean>
</beans>
web.xml
<?xml
version="1.0"
encoding="UTF-8"?>
<web-app
id="WebApp_ID"
version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<display-name>sendingmail-portlet</display-name>
<servlet>
<servlet-name>view-servlet</servlet-name>
<servlet-class>org.springframework.web.servlet.ViewRendererServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>view-servlet</servlet-name>
<url-pattern>/WEB-INF/servlet/view</url-pattern>
</servlet-mapping>
<jsp-config>
<taglib>
<taglib-uri>http://java.sun.com/portlet_2_0</taglib-uri>
<taglib-location>/WEB-INF/tld/liferay-portlet.tld</taglib-location>
</taglib>
<taglib>
<taglib-uri>http://liferay.com/tld/aui</taglib-uri>
<taglib-location>/WEB-INF/tld/aui.tld</taglib-location>
</taglib>
</jsp-config>
</web-app>
EmailForm.jsp
<%@
page language="java"
contentType="text/html;
charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE
html PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@
taglib
uri="http://java.sun.com/portlet_2_0"
prefix="portlet"%>
<portlet:defineObjects
/>
<portlet:actionURL
var="actionOneMethodURL">
<portlet:param
name="action"
value="actionOne"></portlet:param>
</portlet:actionURL>
<center>
<fieldset
style="border:
2px solid #668080;
-moz-border-radius:
7px;
border-radius:
7px;">
<legend
style="font-family:
Verdana, Geneva, sans-serif;
font-size:
18px;
color:
#2E2E00;
border: 1px
solid #668080; -moz-border-radius:
4px;
border-radius:
4px;">Send
Email</legend>
<form
method="post"
action="<%=actionOneMethodURL%>">
<!--
enctype="multipart/form-data" -->
<table
border="0"
width="auto"
align="center"
cellspacing="2"
cellpadding="2">
<tr>
<td
style="width:
20%;"><span
style="font-family:
Verdana, Geneva, sans-serif;
font-size:
13px;">Email
To:</span></td>
<td><input
type="text"
name="mailTo"
size="45"
style="border:
1px solid #5C7A99;
-moz-border-radius:
5px;
border-radius:
5px;"
/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><span
style="font-family:
Verdana, Geneva, sans-serif;
font-size:
13px;">Subject:</span></td>
<td><input
type="text"
name="subject"
size="45"
style="border:
1px solid #5C7A99;
-moz-border-radius:
5px;
border-radius:
5px;"
/></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><span
style="font-family:
Verdana, Geneva, sans-serif;
font-size:
13px;">Message:</span></td>
<td><textarea
cols="60"
rows="10"
name="message"
style="border:
1px solid #5C7A99;
-moz-border-radius:
5px;
border-radius:
5px;"
/></textarea></td>
</tr>
<tr>
<td
style="height:
70px;"> </td>
<td
align="center"><input
type="submit"
value="Send"
style="width:
55px;
height:
40px;
font-size:
13px;"
/></td>
</tr>
</table>
</form>
</fieldset>
</center>
SendEmailAttachController
package
com.java.spring;
import
javax.mail.internet.MimeMessage;
import
javax.portlet.ActionRequest;
import
javax.portlet.ActionResponse;
import
javax.portlet.RenderRequest;
import
javax.portlet.RenderResponse;
import
org.springframework.beans.factory.annotation.Autowired;
import
org.springframework.mail.javamail.JavaMailSender;
import
org.springframework.mail.javamail.MimeMessageHelper;
import
org.springframework.mail.javamail.MimeMessagePreparator;
import
org.springframework.stereotype.Controller;
import
org.springframework.ui.Model;
import
org.springframework.web.bind.annotation.RequestMapping;
import
org.springframework.web.portlet.bind.annotation.ActionMapping;
import
org.springframework.web.portlet.bind.annotation.RenderMapping;
@Controller
@RequestMapping("/sendEmail.do")
public
class
SendEmailAttachController {
@Autowired
private
JavaMailSender mailSender;
@RenderMapping
public
String handleRenderRequest(RenderRequest request,
RenderResponse
response, Model model) {
return
"EmailForm";
}
@ActionMapping(params
= "action=actionOne")
public
void
sendEmail(ActionRequest request,ActionResponse response) {
//
reads form input
final
String emailTo = request.getParameter("mailTo");
final
String subject = request.getParameter("subject");
final
String message = request.getParameter("message");
//
for logging
System.out.println("emailTo:
" + emailTo);
System.out.println("subject:
" + subject);
System.out.println("message:
" + message);
mailSender.send(new
MimeMessagePreparator() {
@Override
public
void
prepare(MimeMessage mimeMessage) throws
Exception {
MimeMessageHelper
messageHelper = new
MimeMessageHelper(
mimeMessage,
true,
"UTF-8");
messageHelper.setTo(emailTo);
messageHelper.setSubject(subject);
messageHelper.setText(message);
}
});
}
}
List of jars for this program:
List of jars for this program:
commons-beanutils.jar
commons-collections.jar
commons-fileupload.jar
commons-io.jar
commons-lang.jar
ext-training-ext-util-bridges.jar
ext-training-ext-util-java.jar
ext-training-ext-util-taglib.jar
jstl-api.jar
jstl-impl.jar
spring-aop.jar
spring-asm.jar
spring-beans.jar
spring-context-support.jar
spring-context.jar
spring-core.jar
spring-expression.jar
spring-jdbc.jar
spring-transaction.jar
spring-web-portlet.jar
spring-web-servlet.jar
spring-web.jar
¿where do you place those jars?
ReplyDeleteYou can place those jars in lib folder or you can add in liferaypluginpackage.properties also.
ReplyDeleteedirne
ReplyDeletetrabzon
adana
yozgat
EJBT