Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

How to fetch emailParams into email template?

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

25-06-2019

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

}

}

}

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile

Avatar
Validate 1
Level 3
tahir1601
Level 3

Likes

21 likes

Total Posts

41 posts

Correct Reply

2 solutions
Top badges earned
Validate 1
Give Back 5
Give Back 3
Give Back
Boost 5
View profile
tahir1601
Level 3

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)

Avatar

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile

Avatar
Coach
MVP
Arun_Patidar
MVP

Likes

1,345 likes

Total Posts

3,220 posts

Correct Reply

914 solutions
Top badges earned
Coach
Contributor 2
Ignite 10
Give Back 700
Boost 1000
View profile
Arun_Patidar
MVP

25-06-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