Send Email HTML Format Java

Send Email HTML Format Java

Sending plain text email using java is very straight forward you can see this tutorial. To send email using java in HTML format, where you have to create some grid to show data inside it. To generate email in html format and we will use Apache Velocity template engine which provides template language that can be reference to object created in java code. Using template for sending email will be clean separation between model and view.

Note: To do complete unit testing with dummy SMTP server please use this how to use FAKESMTP server tutorial

  • Final maven project structure:

Send Email HTML Format Java

As you see above project structure we have created three below template to process send data:

  • Sample.vm – Static data template:

  •  SampleRenderList.vm – Template which will loop through list object

  • SampleRenderMap.vm – Template which will loop through map object

  • SendEmailVelocityTemplate.java – This class will create and process all above template data and finally send email to the user:

  • Output:

Send Email HTML Format Java

download Download project: SendEmailVelocityTemplate

Leave a Reply

Your email address will not be published. Required fields are marked *