Aem cq mail service
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.