AEM Email API Issue. | Community
Skip to main content
chamu0003
Level 2
November 14, 2016

AEM Email API Issue.

  • November 14, 2016
  • 3 replies
  • 6956 views

Hi ,

Can anyone please help me what's wrong in my email sending  code.

Node templateNode = adminSession.getNode("/etc/workflow/notification/email/demo/choosesite.txt"); log.info("admin session:: "+adminSession+".."+templateNode); final Map<String, String> parameters = new HashMap<String, String>(); parameters.put("title", "page activation"); parameters.put("name", "chamu"); parameters.put("id", "chamu@gmail.com"); parameters.put("prefix", "localhost"); parameters.put("path", "/content/demo/test.html"); */ final MailTemplate mailTemplate = MailTemplate.create(templateNode.getPath(),templateNode.getSession()); HtmlEmail  email = mailTemplate.getEmail(StrLookup.mapLookup(parameters),HtmlEmail.class); email.addTo("chamu0001@gmail.com"); //email.addTo(new ArrayList<>()); MessageGateway<HtmlEmail> messageGateway = this.messageGatewayService.getGateway(HtmlEmail.class); messageGateway.send(email);

it's always throwing below error .

Caused by: java.lang.LinkageError: loader constraint violation: when resolving method "com.day.cq.commons.mail.MailTemplate.getEmail(Lorg/apache/commons/lang/text/StrLookup;Ljava/lang/Class;)Lorg/apache/commons/mail/Email;" the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) of the current class, com/demo/aem/workflow/exec/RBSpawnSubWorkflowsProcess, and the class loader (instance of org/apache/felix/framework/BundleWiringImpl$BundleClassLoaderJava5) for resolved class, com/day/cq/commons/mail/MailTemplate, have different Class objects for the type s/lang/text/StrLookup;Ljava/lang/Class;)Lorg/apache/commons/mail/Email; used in the signature

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.

3 replies

smacdonald2008
Level 10
November 14, 2016

Are you following an online doc? If so - can you reference it so community can see if that is reproducible.

We have a MessageGateWay article - but that is part of a custom workflow step.

http://helpx.adobe.com/experience-manager/using/creating-custom-aem-workflow-steps.html

It does not use the email template as is shown here. 

mohanb
Level 4
November 14, 2016

try restarting bundles, i had faced issues and it was due to resolution dependency issues. restarting components/ respective bundles resolved issue.

Level 3
November 15, 2016

Hi,

You can see the below servlet code. we are hitting the below servlet through action="/bin/hello" and from that servlet we are sending the email ,we are able to get the email also.

Maven dependency:

<dependency>
            <groupId>javax.mail</groupId>
            <artifactId>javax.mail-api</artifactId>
            <version>1.5.1</version>
        </dependency>

and if your system pointing  port no 465 of smtp.gmail.com ,use this code 

props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.ssl.enable", "true");
        //    props.put("mail.smtp.starttls.enable", "true");
            props.put("mail.smtp.host", "smtp.gmail.com");
            props.put("mail.smtp.port", "465");

or else   if your system pointing  port no 587 of smtp.gmail.com ,use this code

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");

 

 

servlet code :

@SlingServlet(paths = "/bin/hello", methods = "{GET, POST}")

public class MailTest extends SlingAllMethodsServlet {

    private static final long serialVersionUID = 1L;

    @Override
    protected void doPost(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServletException,
            IOException {
        try {
            final String from = "aemwebsiteenquiryform@gmail.com";
            final String password = "123";

            String email = request.getParameter("email");
            String query = request.getParameter("query");
            
            
            System.out.println(email + "--" + query);

            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");

            Session session = Session.getInstance(props,
                    new javax.mail.Authenticator() {
                        protected PasswordAuthentication getPasswordAuthentication() {
                            return new PasswordAuthentication(from, password);
                        }
                    });

            Message nameOfStationMessages = new MimeMessage(session);
            nameOfStationMessages.setFrom(new InternetAddress(from));
            nameOfStationMessages.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(email));
            nameOfStationMessages.setText("Suggestion/Query: " + query);
            Transport.send(nameOfStationMessages);
           System.out.println("hello");
            response.sendRedirect("/content/transport/fr.html");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Adobe Employee
June 7, 2019

veerareddyc25475686

I am facing the same issue, Can you share the solution for this error?

Adobe Employee
June 10, 2019

Thanks arunpatidar26​. That was helpful