Search code examples
thymeleafmailto

Custom mailto: link using Thymeleaf


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:[email protected]">

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}">

Solution

  • Try the following code:

    <td><a th:href="'mailto:' + ${users.email}">Send email </a></td>