How to fetch emailParams into email template? | Adobe Higher Education
Skip to main content
Level 3
June 25, 2019
Répondu

How to fetch emailParams into email template?

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

}

}

}

Ce sujet a été fermé aux réponses.
Meilleure réponse par tahir1601

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}

2 commentaires

arunpatidar
Community Advisor
Community Advisor
June 25, 2019

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
tahir1601AuteurRéponse
Level 3
June 26, 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}