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

Aem cq mail service

Avatar

Avatar
Validate 10
Level 3
arjuns71585267
Level 3

Likes

11 likes

Total Posts

65 posts

Correct Reply

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

Avatar
Validate 10
Level 3
arjuns71585267
Level 3

Likes

11 likes

Total Posts

65 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile
arjuns71585267
Level 3

13-12-2018

Was trying to send email using cq mail service by creating a test email component. I have created  a jsp for the same. But the component shows error on rendering

<%@include file="/libs/foundation/global.jsp"%>

<%@page import="com.adobe.acs.commons.email.EmailService,java.util.*"%><%

// Get the OSGi Email Service

EmailService emailService = sling.getService(EmailService.class);

// Specify the template file to use (this is an absolute path in the JCR)

String templatePath = "/etc/notification/email/default/emailTemplate.txt";

//Set the dynamic variables of your email template

Map<String, String> emailParams = new HashMap<String,String>();

emailParams.put("body","hello there");

//  Customize the sender email address - if required

emailParams.put("senderEmailAddress","abcd@example.com");

emailParams.put("senderName","David Smith");

// Array of email recipients

String[] recipients = { "s.arjun36@gmail.com"};

// emailService.sendEmail(..) returns a list of all the recipients that could not be sent the email

// An empty list indicates 100% success

List<String> failureList = emailService.sendEmail(templatePath, emailParams, recipients);

if (failureList.isEmpty()) {

out.println("Email sent successfully to the recipients");

} else {

out.println("Email sent failed");

}

%>

This is my code and the following is the error message I receive on rendering the component

Error during include of component '/apps/emailtest/text'

Error Message:

org.apache.sling.api.scripting.ScriptEvaluationException: org.apache.sling.scripting.jsp.jasper.JasperException: Unable to compile class for JSP:  An error occurred at line: 19 in the generated java file Only a type can be imported. com.adobe.acs.commons.email.EmailService resolves to a package  An error occurred at line: 5 in the jsp file: /apps/emailtest/text/text.jsp EmailService cannot be resolved to a type 2:      <%@page import="com.adobe.acs.commons.email.EmailService,java.util.*"%><% 3: 4:      // Get the OSGi Email Service 5:      EmailService emailService = sling.getService(EmailService.class); 6: 7:      // Specify the template file to use (this is an absolute path in the JCR) 8:      String templatePath = "/etc/notification/email/default/emailTemplate.txt";   An error occurred at line: 5 in the jsp file: /apps/emailtest/text/text.jsp EmailService cannot be resolved to a type 2:      <%@page import="com.adobe.acs.commons.email.EmailService,java.util.*"%><% 3: 4:      // Get the OSGi Email Service 5:      EmailService emailService = sling.getService(EmailService.class); 6: 7:      // Specify the template file to use (this is an absolute path in the JCR) 8:      String templatePath = "/etc/notification/email/default/emailTemplate.txt";

Could anyone please help me out for this? Thanks in advance.

Replies

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,153 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,153 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

13-12-2018

Do you have ACS Common package/dependancy in place?

<!-- https://mvnrepository.com/artifact/com.adobe.acs/acs-aem-commons-bundle -->

<dependency>

    <groupId>com.adobe.acs</groupId>

    <artifactId>acs-aem-commons-bundle</artifactId>

    <version>2.1.0</version>

</dependency>

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

13-12-2018

Write a custom Service that uses the MessageGatewayService. Its quite easy to use. See this article where we use it within a workflow step -

Adobe Experience Manager Help | Creating an Adobe Experience Manager 6.4 custom workflow step that u...

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

13-12-2018

Java code:

MessageGateway<Email> messageGateway;

             

        //Set up the Email message

        Email email = new SimpleEmail();

             

        //Set the mail values

        String emailToRecipients = "scottm@adobe.com";

        String emailCcRecipients = "ratna1.kumar@gmail.com";

         

        email.addTo(emailToRecipients);

        email.addCc(emailCcRecipients);

        email.setSubject("AEM Custom Step");

        email.setFrom("scottm@adobe.com");

        email.setMsg("This message is to inform you that the AEM content has been deleted");

         

        //Inject a MessageGateway Service and send the message

        messageGateway = messageGatewayService.getGateway(Email.class);

     

        // Check the logs to see that messageGateway is not null

        messageGateway.send((Email) email);

Avatar

Avatar
Validate 10
Level 3
arjuns71585267
Level 3

Likes

11 likes

Total Posts

65 posts

Correct Reply

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

Avatar
Validate 10
Level 3
arjuns71585267
Level 3

Likes

11 likes

Total Posts

65 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile
arjuns71585267
Level 3

14-12-2018

I didn't build it using maven. just configured the day.cq.mail service

Avatar

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile

Avatar
Give Back 50
Employee
Feike_Visser1
Employee

Likes

247 likes

Total Posts

970 posts

Correct Reply

221 solutions
Top badges earned
Give Back 50
Give Back 5
Give Back 3
Give Back 25
Give Back 10
View profile
Feike_Visser1
Employee

14-12-2018

the error indicates that the class can't found. Either the code is not deployed, or the bundle is not active.

can you check at /system/console/services whether the service is available?

Avatar

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile

Avatar
Validate 25
Level 10
smacdonald2008
Level 10

Likes

1,406 likes

Total Posts

12,671 posts

Correct Reply

2,278 solutions
Top badges earned
Validate 25
Validate 10
Validate 1
Give back 900
Give back 600
View profile
smacdonald2008
Level 10

14-12-2018

I find the MessageGatewayService API very reliable to use and do not see issues when using it.

Feike is correct - in your example - the error means that com.adobe.acs.commons.email.EmailService is not found. Ensure that this bundle is in active state.

Or write your own bundle using the API I referred to.

Avatar

Avatar
Validate 10
Level 3
arjuns71585267
Level 3

Likes

11 likes

Total Posts

65 posts

Correct Reply

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

Avatar
Validate 10
Level 3
arjuns71585267
Level 3

Likes

11 likes

Total Posts

65 posts

Correct Reply

1 solution
Top badges earned
Validate 10
Validate 1
Ignite 5
Ignite 3
Ignite 1
View profile
arjuns71585267
Level 3

17-12-2018

I cannot find the service under the services. Attaching the screenshot for your reference.

1648512_pastedImage_0.png

Avatar

Avatar
Give Back
Level 1
KetkiNeema16
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Give Back
View profile

Avatar
Give Back
Level 1
KetkiNeema16
Level 1

Likes

0 likes

Total Posts

1 post

Correct Reply

0 solutions
Top badges earned
Give Back
View profile
KetkiNeema16
Level 1

29-11-2019

Hi smacdonald2008​, Can we track bounced mails from MessageGateway API ?

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,153 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,279 likes

Total Posts

3,153 posts

Correct Reply

889 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

30-11-2019

I believe you can get bounceback mail information from SMTP server.

for example, google SMTP server provides feeds for a bounce-back and other kinds of emails.