Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

Regarding Mail issue in publish instance

Avatar

Avatar
Validate 10
Level 2
veerareddyc2547
Level 2

Likes

5 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile

Avatar
Validate 10
Level 2
veerareddyc2547
Level 2

Likes

5 likes

Total Posts

36 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Boost 5
Boost 3
Boost 1
View profile
veerareddyc2547
Level 2

26-07-2016

Hi All,
 
We have created a custom mail service. the code is working fine in author instance but it is not working in publish instance .can any one please suggest me to solve this problem and what configuration should i do in publish instace.

here is my code.

form component:
---------------
<%@include file="/libs/foundation/global.jsp"%>

<script>
 
$(document).ready(function() {
   
    $('body').hide().fadeIn(5000);
          
$('#submit').click(function() {
    var failure = function(err) {
             alert("Unable to retrive data "+err);
   };
   var name = $("#user_name").val();
var email = $("#email").val();
 
    //Use JQuery AJAX to perform a GET to the AEM Sling Servlet that uses Sling Models
    $.ajax({
         type: 'GET',    
         url:'/bin/slingmodel',
        data:"name=" + name+"&email="+email,
         success: function(msg){
             $('#json').val(msg);   
         }
     });
  });

}); // end ready
</script>


<form method='post' action="javascript:mail();" >
<input type="text" class="input-large" id="user_name" name="name">
<input type="text" class="input-large" id="email" name="email">
<button type="submit" class="btn btn-primary" id="submit">Submit</button>
</form>


and java code to send mail:
---------------------------
package com.rajasthan.itportal.sightly;

import java.io.IOException;
import java.util.Properties;

import javax.mail.Message;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.servlet.ServletException;

import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ResourceResolverFactory;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
 
 
 
 
@SlingServlet(paths="/bin/slingmodel", methods="GET")
public class SlingModels extends SlingAllMethodsServlet{
 
    private static final long serialVersionUID = 1L;
    Logger logger = LoggerFactory.getLogger(this.getClass());
    @Reference
    ResourceResolverFactory resourceResolverFactory;    
    ResourceResolver resourceResolver;
    public void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)throws ServletException,IOException{
        logger.info("inside sling model test servlet");
        response.setContentType("text/html");
        try {
            final String from = "aemwebsiteenquiryform@gmail.com";
            final String password = "Robotics@123";

            String name = request.getParameter("name");
            String email = request.getParameter("email");
            System.out.println(name);
            System.out.println(email);
            Properties props = new Properties();
            props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", "smtp.gmail.com");
            props.put("mail.smtp.port", "587");
            System.out.println("2");
            Session session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(from, password);
                        }
                    });
            System.out.println("3");
            Message nameOfStationMessages = new MimeMessage(session);
            
            nameOfStationMessages.setFrom(new InternetAddress(from));
            System.out.println("5");
            nameOfStationMessages.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(email));
            nameOfStationMessages.setText("Suggestion/Query: " + name);
            System.out.println("6");
            
            
            System.out.println("7");
            Transport.send(nameOfStationMessages);
            
            System.out.println("hit");
            
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        finally{
            if(resourceResolver.isLive())
                resourceResolver.close();
        }
         
     
    }
 
}

Replies

Avatar

Avatar
Validate 50
Level 5
askdctm
Level 5

Likes

48 likes

Total Posts

476 posts

Correct Reply

7 solutions
Top badges earned
Validate 50
Validate 25
Validate 10
Validate 1
Boost 5
View profile

Avatar
Validate 50
Level 5
askdctm
Level 5

Likes

48 likes

Total Posts

476 posts

Correct Reply

7 solutions
Top badges earned
Validate 50
Validate 25
Validate 10
Validate 1
Boost 5
View profile
askdctm
Level 5

27-07-2016

Hi,

Not pretty sure, but one thing that you can check is the path provided for the servlet '/bin/slingmodel'. 

May be try with /content/slingmodel or some path, because if the /bin etc location is whitelisted, could contribute to the issue.

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,168 likes

Total Posts

6,289 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,168 likes

Total Posts

6,289 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

27-07-2016

Is there some error coming up in publish instance ?

I hope everything is replicated to publish instance (OSGI service, Component, JSP,  JS etc.)

~kautuk

Avatar

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,168 likes

Total Posts

6,289 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile

Avatar
Establish
Community Manager
kautuk_sahni
Community Manager

Likes

1,168 likes

Total Posts

6,289 posts

Correct Reply

1,144 solutions
Top badges earned
Establish
Coach
Originator
Contributor 2
Contributor
View profile
kautuk_sahni
Community Manager

27-07-2016

Check on your publish on localhost:4503/sytem/console/requests the trace of the request, which does not work.

Also Check in crx-quickstart/logs/error.log

Reference Link:- https://forums.adobe.com/message/4263826#4263826

~kautuk