@Override protected void doPost(SlingHttpServletRequest request,SlingHttpServletResponse response) throws ServletException, IOException {
  response.setContentType("application/json");
  PrintWriter writer=response.getWriter();
  boolean notRobot=recaptchaService.validate(request);
  if (notRobot) {
    final String submitterName=request.getParameter("name");
    final String submitterEmail=request.getParameter("email");
    final String submitterMessage=request.getParameter("message");
    if (StringUtils.isNotEmpty(submitterName) && StringUtils.isNotEmpty(submitterName) && StringUtils.isNotEmpty(submitterName)) {
      final String body=String.format(BODY,submitterName,submitterEmail,submitterMessage);
      final boolean result=emailService.sendMail(SUBJECT,body);
      if (result) {
        response.setStatus(SlingHttpServletResponse.SC_OK);
        sendResponse(writer,SlingHttpServletResponse.SC_OK,"Email was sent successfully.");
      }
 else {
        response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        sendResponse(writer,SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Internal server error.");
      }
    }
 else {
      response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
      sendResponse(writer,SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR,"Submission was missing the message, name or email.");
    }
  }
 else {
    response.setStatus(SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    sendResponse(writer,SlingHttpServletResponse.SC_INTERNAL_SERVER_ERROR,"The reCAPTCHA service determined that you were a robot.");
  }
}

@ Override protected void doPost ( SlingHttpServletRequest request , SlingHttpServletResponse response ) throws ServletException , IOException { response . setContentType ( "application/json" ) ; PrintWriter writer = response . getWriter ( ) ; boolean notRobot = recaptchaService . validate ( request ) ; if ( notRobot ) { final String submitterName = request . getParameter ( "name" ) ; final String submitterEmail = request . getParameter ( "email" ) ; final String submitterMessage = request . getParameter ( "message" ) ; if ( StringUtils . isNotEmpty ( submitterName ) && StringUtils . isNotEmpty ( submitterName ) && StringUtils . isNotEmpty ( submitterName ) ) { final String body = String . format ( BODY , submitterName , submitterEmail , submitterMessage ) ; final boolean result = emailService . sendMail ( SUBJECT , body ) ; if ( result ) { response . setStatus ( SlingHttpServletResponse . SC_OK ) ; sendResponse ( writer , SlingHttpServletResponse . SC_OK , "Email was sent successfully." ) ; } else { response . setStatus ( SlingHttpServletResponse . SC_INTERNAL_SERVER_ERROR ) ; sendResponse ( writer , SlingHttpServletResponse . SC_INTERNAL_SERVER_ERROR , "Internal server error." ) ; } } else { response . setStatus ( SlingHttpServletResponse . SC_INTERNAL_SERVER_ERROR ) ; sendResponse ( writer , SlingHttpServletResponse . SC_INTERNAL_SERVER_ERROR , "Submission was missing the message, name or email." ) ; } } else { response . setStatus ( SlingHttpServletResponse . SC_INTERNAL_SERVER_ERROR ) ; sendResponse ( writer , SlingHttpServletResponse . SC_INTERNAL_SERVER_ERROR , "The reCAPTCHA service determined that you were a robot." ) ; } }
send email on post to servlet . the submission is verified through the recaptcha service before submitting . upon completion , a json response is returned .
