Hi,
I'm trying to send e-mail with some information provided via <form> but I'm not really sure how to do it. I've understood that I need to create Servlet that process the form data and sends the email. I've tried to follow these instructions but it's not clear enough for CQ5/Servlet(I don't have any experience with Servlets) newbie like me. I've successfully created the component(I already have some experiences with components) and bundle under /apps/myapp/src but I don't know what to do next and where to put all the code. I'm getting confused in the "Creating the HTML Email Servlet" part. Where should I put that code there? Into my component or into the Servlet? I think I should put this
String template = properties.get("emailTemplate","/notset"); Resource templateRsrc = request.getResourceResolver().getResource(template); if (templateRsrc.getChild("file") != null) { templateRsrc = templateRsrc.getChild("file"); } if (templateRsrc == null) { throw new IllegalArgumentException("Missing template: " + template); } final MailTemplate mailTemplate = MailTemplate.create(templateRsrc.getPath(), templateRsrc.getResourceResolver().adaptTo(Session.class)); final HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(properties), HtmlEmail.class);
to the component code but how do I pass all the info to the servlet after the user submits the form?
So basically I need to get data from html form(created with my component) and then send it to some e-mail. Can you help me? Some commented working code will be enough, I can program in Java so I can edit it to my needs.
BTW I the mailing settings in OSGi are already properly set.
Thanks for any help and sorry for my poor english and poor description of the problem.
Solved! Go to Solution.
Views
Replies
Total Likes
A servlet is just a Java class that implements a specific interface, making it able to process HTTP requests. Those HTTP requests are usually made by an HTML form submission, but nothing about that is required. The servlet must be registered to a specific set of criteria (a path location, resource type, etc.) so that Sling knows when to invoke the servlet as the processing mechanism for an HTTP request. High level, here's what you'll need to do:
Hope this helps.
Views
Replies
Total Likes
A servlet is just a Java class that implements a specific interface, making it able to process HTTP requests. Those HTTP requests are usually made by an HTML form submission, but nothing about that is required. The servlet must be registered to a specific set of criteria (a path location, resource type, etc.) so that Sling knows when to invoke the servlet as the processing mechanism for an HTTP request. High level, here's what you'll need to do:
Hope this helps.
Views
Replies
Total Likes
You can create your own code to perform this entire workflow. TO see how to write a Sling servlet -- see:
1. http://scottsdigitalcommunity.blogspot.ca/2013/06/posting-form-data-to-adobe-cq-using.html -- this article will teach you how to create a Sling Servlet in CQ. Now instead of encoding the passed in form data to JSON data (as shown in this article) -- create an email service and email the data passed to the Sling Servlet.
2 - THis article discusses how to create a custom email service within CQ: http://scottsdigitalcommunity.blogspot.ca/2012/07/creating-custom-cq-email-services.html. This article passed data form the form to CQ by invoking an OSGi from a JSP page and passing in the data.
So you can combine the articles -- post form data to a Sling Servlet and then call the Email service. Or just follow article 2 and simply invoke the OSGi operation from a JSP.
Hope this helps.
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies