Email service setup



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] service: Uncaught Throwable

java.lang.NullPointerException: null

at [com.kohler.jacobdelafon.core:1.0.0.SNAPSHOT]

at com.kohler.jacobdelafon.core.servlets.ContactServlet.doPost( [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.sample.myapp.core.beans.EmailDetails;

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

public class ContactEmailService {


EmailService emailService;

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

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

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

public void sendEmail() {


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

emailParams.put("senderEmailAddress", "");

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


String[] recipients = { "", "" };


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


if (failureList.isEmpty()) {"successfully sent");

} else {"failed to deliver");