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");
}
}
}
Solved! Go to Solution.
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}
Views
Replies
Total Likes
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
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}
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies