Search code examples
jakarta-maildata-extraction

How to extract data from email body using Java


I am able to read the email mail body. The MimeType is text/html. Below is the email body message and from these how to extract certain information as

Transaction type = Vehicle Client Name = Roja H, Client Mobile Number = 7418529632

<html>
<head>
    <title>
       Demo Example
    </title>
</head>
<body>
    <div class="content">
        <p>
            Dear User,
        </p>
        <p>
            A Transaction has been created for :
        </p>
        <p>
            <table >
                <tr>
                    <td class="col-heading">Transaction Type </td>
                    <td>:</td>
                    <td>Vehicle</td>
                </tr>

                <tr>
                    <td class="col-heading">Client Name </td>
                    <td>:</td>
                    <td>Roja H</td>
                </tr>

                <tr>
                    <td class="col-heading">Client Mobile Number</td>
                    <td>:</td>
                    <td>7418529632</td>
                </tr>

                <tr>
                    <td class="col-heading">Client Email Address</td>
                    <td>:</td>
                    <td>clientAddresss@address.com</td>
                </tr>
                <tr>
                    <td class="col-heading">Group</td>
                    <td>:</td>
                    <td>Examplegroup</td>
                </tr>
            </table>
        </p>
    </div>
</html>

Solution

  • Obviously you just need to parse the html. You can do it yourself, you can use regular expressions to help, or you can use a library such as jsoup to fully parse the html.