Expand my Community achievements bar.

SOLVED

How to fetch emailParams into email template?

Avatar

Level 4

Hi,

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 {

@Reference

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<>();

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

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

emailParams.put("senderEmailAddress", "test@gmail.com");

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

emailDetails.setEmailParams(emailParams);

String[] recipients = { "myemail@gmail.com" };

emailDetails.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");

}

}

}

1 Accepted Solution

Avatar

Correct answer by
Level 4

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}

View solution in original post

2 Replies

Avatar

Community Advisor

Hi,

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



Arun Patidar

Avatar

Correct answer by
Level 4

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}