Requirement:- send email upon form submission.
Below is my class. I am getting null pointer exception when i print the emailService. Can anyone help me out please.
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;
Arun Patidarsmacdonald2008
@Component(immediate = true, service = ContactEmailService.class)
public class ContactEmailService {
@Reference
private EmailService mailService;
Logger logger = LoggerFactory.getLogger(this.getClass());
EmailDetails details = new EmailDetails(); //bean class
private Map<String, String> emailParams = new HashMap<>();
public void sendEmail() {
logger.info("email service"+mailService); // prints null
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", "sample@example.com" };
details.setRecipients(recipients);
List<String> failureList = mailService.sendEmail(details.getTemplatePath(), details.getEmailParams(),details.getRecipients()); //throws null pointer exception
logger.info(""+failureList.size());
if (failureList.isEmpty()) {
logger.info("successfully sent");
} else {
logger.info("failed to deliver");
}
}
}