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

Email service setup

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

21-06-2019

Hey All,

I am stuck at a point, request someone to help me out.

I have setup email service by following the tutorial below

AEM Component To Send An Email Tutorial | A Developers Blog

Email API

however my requirement is i am passing values to emailservice in java class rather than in jsp. I am getting a null pointer error as below

21.06.2019 05:09:01.273 *ERROR* [0:0:0:0:0:0:0:1 [1561111741271] POST /bin/contactServlet HTTP/1.1] org.apache.sling.engine.impl.SlingRequestProcessorImpl service: Uncaught Throwable

java.lang.NullPointerException: null

at com.kohler.jacobdelafon.core.services.impl.ContactEmailService.sendEmail(ContactEmailService.java:31) [com.kohler.jacobdelafon.core:1.0.0.SNAPSHOT]

at com.kohler.jacobdelafon.core.servlets.ContactServlet.doPost(ContactServlet.java:48) [com.kohler.jacobdelafon.core:1.0.0.SNAPSHOT]

Below is my java class

import java.util.HashMap;

import java.util.List;

import java.util.Map;

import org.osgi.service.component.annotations.Component;

import org.osgi.service.component.annotations.Reference;

import org.slf4j.Logger;

import org.slf4j.LoggerFactory;

import com.adobe.acs.commons.email.EmailService;

import com.sample.myapp.core.beans.EmailDetails;

@Component(immediate = true, service = ContactEmailService.class)

public class ContactEmailService {

@Reference

EmailService emailService;

Logger logger = LoggerFactory.getLogger(this.getClass());

EmailDetails details = new EmailDetails(); //bean class

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

public void sendEmail() {

details.setTemplatePath("/etc/notification/email/kohler/contact_email.txt");

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

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

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

details.setEmailParams(emailParams);

String[] recipients = { "test@gmail.com", "abc@example.com" };

details.setRecipients(recipients);

List<String> failureList = emailService.sendEmail(details.getTemplatePath(), details.getEmailParams(),

details.getRecipients());

logger.info(""+failureList.size());

if (failureList.isEmpty()) {

logger.info("successfully sent");

} else {

logger.info("failed to deliver");

}

}

}