How to fetch emailParams into email template?

tahir1601 25-06-2019


Can someone help me out in fetching emailparams into email template? in this case i want to fetch first name in the email template.

Below is my servlet code

public class ContactServlet extends HttpServlet {


private EmailService emailService;

private static final long serialVersionUID = -6506682026701304964L;

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

private String templatePath;smacdonald2008Joerg HohArun Patidar

private Map<String, String> emailParams;

private String[] recipients;

protected void doPost(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {

EmailDetails emailDetails=new EmailDetails();

String firstName = request.getParameter("firsrname");               //fetching via ajax Post

emailParams=new HashMap<>();


emailParams.put("First Name", firstName);

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

emailParams.put("senderName", "test");


String[] recipients = { "" };


List<String> failureList = emailService.sendEmail(details.getTemplatePath(), details.getEmailParams(), details.getRecipients());"" + failureList.size());

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

} else {"failed to deliver");




Accepted Solutions (1)

Accepted Solutions (1)

tahir1601 25-06-2019

I was able to fetch it in email template as ${First Name}

The emailParams takes a key value where value can be accessed by key in email template as ${key}

Answers (1)

Answers (1)



What issue are you facing here?

Is it working for hard coded values?

Is returns request.getParameter("firsrname"); null?

If everything fine in code then in templates you can access like

Hello ${firstname}

more info

Email API