Custom mailto: link using Thymeleaf

Viewed 4824

I am working with project using Spring and Thymeleaf. I have list of users. I would like to create contact link using mailto:

<a href="mailto:name@email.com">

I am displaying list of users like this:

<tr th:each="users : ${users}">
    <td th:text="${users.id}"></td>
    <td th:text="${users.firstname}"></td>
    <td th:text="${users.lastname}"></td>
    <td th:text="${users.email}"></td>
</tr>

So what I would like to achieve is that mailto suits every new professor and his email without me writing it manually. I am thinking if is possible to write something like this:

<td><a th:href = "mailto:${users.email}">
2 Answers

You can do this more safely and with extra parameters using link syntax:

<td><a th:href="@{mailto:{to}(to=${users.email})}">Send email </a></td>

This allows you to also pass CC, Subject and Body:

<td><a th:href="@{mailto:{to}(to=${users.email},subject=${subj},body=${body})}">Send email </a></td>
Related