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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Adobe Summit 2023 [19th to 23rd March, Las Vegas and Virtual] | Complete AEM Session & Lab list

AEM Email API Issue.


Level 2

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");"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", ""); 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(""); //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 ";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

8 Replies


Level 10

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.

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


Level 4

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


Level 3


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:


and if your system pointing  port no 465 of ,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("", "");
            props.put("mail.smtp.port", "465");

or else   if your system pointing  port no 587 of ,use this code

props.put("mail.smtp.auth", "true");
            props.put("mail.smtp.starttls.enable", "true");
            props.put("", "");
            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;

    protected void doPost(SlingHttpServletRequest request,
            SlingHttpServletResponse response) throws ServletException,
            IOException {
        try {
            final String from = "";
            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("", "");
            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.setText("Suggestion/Query: " + query);
        } catch (Exception e) {


Level 1

Hi @arunpatidar,


I've tried your code sample in my local AEM 6.4 instance. Unfortunately I'm getting an error in that line: 

HtmlEmail email = mailTemplate.getEmail(StrLookup.mapLookup(parameters), HtmlEmail.class);


Here's the excerpt from the error stack trace

org.apache.commons.mail.EmailException: Invalid message supplied

                at org.apache.commons.mail.HtmlEmail.setMsg( []

               at []



Any idea what could cause that error?

Should it work in local in first place?


The ultimate experience is back.

Join us in Vegas to build skills, learn from the world's top brands, and be inspired.

Register Now