Fórumok

Mail through WCM (template's velocity)

Vaibhav Mittal, módosítva 11 év-val korábban

Mail through WCM (template's velocity)

Junior Member Bejegyzések: 54 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzések
Hi All,

I have a structure and a template (applied to structure). Now when i add a web content and chage there structure and template from default to my own st. and tem. I can see the data is coming from the structure the way i have defined in my vm template.
Now my requirement is to add a form in template with two fields,one textbox and a submit button which i can fulfill using form tag in velocity. But how can i add action url so that when i click on submit button an email comes to the specified address ( generating through a loop defined in template which is calling data from structure) and form data gets saved in the database.
I can't use form portlet as i want that functionality in my template's velocity to access email id dynamically.

Regards,
Vaibhav Mittal
Vaibhav Mittal, módosítva 11 év-val korábban

RE: Mail through WCM (template's velocity)

Junior Member Bejegyzések: 54 Csatlakozás dátuma: 2012.07.16. Legújabb bejegyzések
1 out of two issues i have solved. What i did z add the below code into my template

Name: <input id="form" type="text" name="name"/><br/>
<input id="button" type="button" value="Send"/>

then send a ajax call (written in template) on jsp page on click of above button

<script>
$(document).ready(function(){
$("#button").click(function(){
var x=document.getElementById("form").value;
$.ajax({type: "POST",
url:"/your theme name/jsp/form.jsp",
data: {a:x} ,
success:function(result){$("#div1").html(result);}
});
});
});
</script>

and in jsp i write my code for sending mail after configuring smtp server.

<%@ page import="com.liferay.mail.service.MailServiceUtil" %>
<%@ page import="com.liferay.portal.kernel.mail.MailMessage" %>
<%@ page import="com.liferay.util.mail.MailEngine" %>
<%@ page import="com.liferay.util.mail.MailEngineException" %>
<%@ page import="javax.mail.internet.InternetAddress" %>

<% String str = request.getParameter("a"); %>
<%= str %>

<% try{
InternetAddress to = new InternetAddress("abc@gmail.com");
InternetAddress from = new InternetAddress("xyz@gmail.com");
String sub = new String("test");
String body = new String("test-mail");
MailMessage msg = new MailMessage();
msg.setTo(to);
msg.setFrom(from);
msg.setBody(body);
msg.setSubject(sub);
MailServiceUtil.sendEmail(msg);
MailEngine.send(from, to, sub, body);
}
catch (Exception e) {
out.println("can't send mail");
}
%>

Don't forget tocopy the commons-lang.jar-File into your portlet\theme in the following folder: $\docroot\WEB-INF\lib\ from the folder: $\webapps\ROOT\WEB-INF\lib\ or add dependency if you are using maven.
Kumari Anusha Kommuri, módosítva 8 év-val korábban

RE: Mail through WCM (template's velocity)

New Member Bejegyzések: 11 Csatlakozás dátuma: 2016.01.20. Legújabb bejegyzések
Hi... Did u solve this issue? I also have similar requirement. I have tried the ajax code that u posted. But I am getting error at that code. Can u please help me?