This article is for creating simple HTML Styled Email using Java. Its difficult to manage HTML code in java. It will be clumsy when its needed to place some data in that HTML code. To avoid all these problems , I have created 3 simple steps
  1. Prepare HTML mock-up of Email Body
  2. Make your data ready in POJO class
  3. Place your data in HTML code using TemplateMatcher

Prepare HTML mock-up 

First of all, prepare your HTML Email mock-up by using any online HTML editor (codepen, cssdeck etc). Lets send student's progress report as email. Find below mock-up and HTML code for Email body

Mock-up 

HTML Code

<div style="padding:20px">
<h2>Progress Report</h2>
<b>Student Name</b> : Srinivas Dasari<br/>
<b>Role No</b> : 690752021<br/>
<br/>
<table border="1" style="border-collapse:collapse;text-align:center">
  <tr>
    <th style="padding:5px">Subject</th>
    <th style="padding:5px">Grade</th>
  </tr>
  <tr>
    <td>Mathmatics</td>
    <td  style="color:blue">A</td>
  </tr>
   <tr>
    <td>Science</td>
    <td style="color:orange">C</td>
  </tr>
  <tr>
    <td>Economics</td>
    <td style="color:red">D</td>
  </tr> 
</table>
</div>

Make your Data ready 

To fill above mock-up we need student name, id and marks. Lets create pojo with those fields.
public class ProgressReport
{
    private String rollNo;

    private String mathmatics;

    private String name;

    private String economics;

    private String science;

    public String getRollNo ()
    {
        return rollNo;
    }

    public void setRollNo (String rollNo)
    {
        this.rollNo = rollNo;
    }

    public String getMathmatics ()
    {
        return mathmatics;
    }

    public void setMathmatics (String mathmatics)
    {
        this.mathmatics = mathmatics;
    }

    public String getName ()
    {
        return name;
    }

    public void setName (String name)
    {
        this.name = name;
    }

    public String getEconomics ()
    {
        return economics;
    }

    public void setEconomics (String economics)
    {
        this.economics = economics;
    }

    public String getScience ()
    {
        return science;
    }

    public void setScience (String science)
    {
        this.science = science;
    }
}

TemplateMatcher Introduction

To use TemplateMatcher, you need to have jlibs-core jar in build-path. You can download this jar from https://code.google.com/p/jlibs/downloads/list
  1. Create string template using TemplateMatcher
  2. Use that template in strings
  3. Replace the template with suitable data
import jlibs.core.util.regex.TemplateMatcher;

String msg = "Student Name : ${name} \n Student ID : ${id} ";
TemplateMatcher matcher = new TemplateMatcher("${", "}");
Map<String, String> vars = new HashMap<String, String>();
vars.put("name", "srinivas");
vars.put("id", "21");
System.out.println(matcher.replace(msg, vars));
Output will be
Student Name : srinivas 
Student ID : 21

Place Data in your HTML code

Its time to create templates in HTML and replace with pojo data. Lets create templates in HTML code.
<div style="padding:20px">
<h2>Progress Report</h2>
<b>Student Name</b> : ${name}<br/>
<b>Role No</b> : ${id}<br/>
<br/>
<table border="1" style="border-collapse:collapse;text-align:center">
  <tr>
    <th style="padding:5px">Subject</th>
    <th style="padding:5px">Grade</th>
  </tr>
  <tr>
    <td>Mathmatics</td>
    <td  style="color:blue">${mathmatics}</td>
  </tr>
   <tr>
    <td>Science</td>
    <td style="color:orange">${science}</td>
  </tr>
  <tr>
    <td>Economics</td>
    <td style="color:red">${economics}</td>
  </tr> 
</table>
</div>
Use Convert HTML or Text to Javascript or Java variable - Online online tool to convert HTML into Java string, it is easier way.
Final code will be
ProgressReport pr = new ProgressReport();
pr.setName("srinivas");
pr.setRollNo("21");
pr.setMathmatics("A");
pr.setScience("C");
pr.setEconomics("D");
StringBuilder body = new StringBuilder(); 
body.append("<div style=\"padding:20px\">")
     .append("<h2>Progress Report</h2>")
     .append("<b>Student Name</b> : ${name}<br/>")
     .append("<b>Role No</b> : ${id}<br/>")
     .append("<br/>")
     .append("<table border=\"1\" style=\"border-collapse:collapse;text-align:center\">")
     .append("  <tr>")
     .append("    <th style=\"padding:5px\">Subject</th>")
     .append("    <th style=\"padding:5px\">Grade</th>")
     .append("  </tr>")
     .append("  <tr>")
     .append("    <td>Mathmatics</td>")
     .append("    <td  style=\"color:blue\">${mathmatics}</td>")
     .append("  </tr>")
     .append("   <tr>")
     .append("    <td>Science</td>")
     .append("    <td style=\"color:orange\">${science}</td>")
     .append("  </tr>")
     .append("  <tr>")
     .append("    <td>Economics</td>")
     .append("    <td style=\"color:red\">${economics}</td>")
     .append("  </tr> ")
     .append("</table>")
     .append("</div>");
TemplateMatcher matcher = new TemplateMatcher("${", "}");
Map<String, String> vars = new HashMap<String, String>();
vars.put("name", pr.getName());
vars.put("id", pr.getRollNo());
vars.put("mathmatics", pr.getMathmatics());
vars.put("science", pr.getScience());
vars.put("economics", pr.getEconomics());
String emailBody = matcher.replace(body.toString(), vars);

Java function to Send Email 

Just send email using below java function
    public static void sendMail(String mail,String sub,String mess) throws AddressException, MessagingException {
        Logger.info(className, "entering sendMail "+mail);
        Properties props = new Properties();
        props.put("mail.smtp.host", "smtp.gmail.com");
        props.put("mail.smtp.socketFactory.port", "465");
        props.put("mail.smtp.socketFactory.class",
                "javax.net.ssl.SSLSocketFactory");
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.port", "465");
 
        Session session = Session.getDefaultInstance(props,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("enter your gmail here","enter your password here");
                }
            });
 
            MimeMessage message = new MimeMessage(session);
            message.setFrom(new InternetAddress("enter your email here"));
            message.setRecipients(Message.RecipientType.TO,
                    InternetAddress.parse(mail));
            message.setSubject(sub);
            message.setContent(mess,
                    "text/html" );
            Transport.send(message);
        Logger.info(className, "leaving sendMail");
    }
Thank you for reading. I hope it helps

82 comments:

  1. Here we will read about the styled email using java which is a different technique. In this way we can read the things as rushmyessay.com review devlopment and other bloggimng benefits. Gamers will like this blog so much because they are connected with java.

    ReplyDelete
  2. A quality cleaning kit can extend the longevity of your game discs. When purchasing a used game, it could be in any kind of condition. These kits can help you restore your games to working condition, even if they used to be really grungy. Make sure you do your homework to see which one is a good fit for you. There are several options available when it comes to which kit you purchase. https://hackeroffice.com/

    ReplyDelete
  3. I am hoping the same best effort from you in the future as well. In fact your creative writing skills has inspired me. Email List

    ReplyDelete
  4. You there, this is really good post here. Thanks for taking the time to post such valuable information. Quality content is what always gets the visitors coming. buy email list

    ReplyDelete
  5. The article looks magnificent, but it would be beneficial if you can share more about the suchlike subjects in the future. Keep posting. veja aqui como entrar no Hotmail.com da Microsoft

    ReplyDelete
  6. This is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free. hotmail login

    ReplyDelete
  7. Thanks for the blog loaded with so many information. Stopping by your blog helped me to get what I was looking for. LinkedIn Scraper

    ReplyDelete
  8. I am happy to find your distinguished way of writing the post. Now you make it easy for me to understand and implement the concept. Thank you for the post. Email Extractor - Online tool for extracting any email address

    ReplyDelete
  9. i read a lot of stuff and i found that the way of writing to clearifing that exactly want to say was very good so i am impressed and ilike to come again in future.. email extractor vs atomic

    ReplyDelete
  10. Excellent to be visiting your blog again, it has been months for me. Rightly, this article that I've been served for therefore long. I want this article to finish my assignment within the faculty, and it has the same topic together with your article. Thanks for the ton of valuable help, nice share. what is gmass in gmail

    ReplyDelete
  11. For this web site, you will see our account, remember to go through this info. Can you scrape Google Maps?

    ReplyDelete
  12. I love this. It is soo informative. Are you also searching for cheap assignment writing services we are the best solution for you. We are best known for delivering the best services to students without having to break the bank

    ReplyDelete
  13. A quality cleaning kit can extend the longevity of your game discs. When purchasing a used game, it could be in any kind of condition. These kits can help you restore your games to working condition, even if they used to be really grungy. Make sure you do your homework to see which one is a good fit for you. There are several options available when it comes to which kit you purchase:
    Serif Affinity Photo Activator

    ReplyDelete
  14. restore your games to working condition, even if they used to be really grungy. Make sure you do your homework to see which one is a good fit for you. Wondershare UniConverter Ultimate crack

    ReplyDelete
  15. Here we will read about the styled email using java which is a different technique. In this way we can read the things as review devlopment and other bloggimng benefits.
    Visit here

    ReplyDelete
  16. This is such a great resource that you are providing and you give it away for free what is use java program pls vist my site

    ReplyDelete
  17. Here we will read about the styled email using java which is a different technique. In this way we can read the things as review devlopment and other bloggimng benefits.Activators for Windows

    ReplyDelete
  18. A quality cleaning kit can extend the longevity of your game discs. When purchasing a used game, it could be in any kind of condition. These kits can help you restore your games to working condition, even if they used to be really grungy. I love this. It is soo informative. Are you also searching for cheap assignment writing services we are the best solution for you.
    https://serialkeygens.com/advanced-systemcare-ultimate/

    ReplyDelete
  19. Here we will read about the styled email using java which is a different technique. In this way we can read the things as review devlopment and other bloggimng benefits.Activators for Windows
    Cinema 4D

    ReplyDelete
  20. Insert Image Directly into an HTML Template Using Javamail This HTML mail ... Email API provides the capability to led the file format of felt provided. Voicemod Pro

    ReplyDelete
  21. i've learnt all the basics of web programing from hereWINRAR 6

    ReplyDelete
  22. Moqups is a streamlined and intuitive web app that helps you create and collaborate on wireframes, mockups, diagrams and prototypes — for any type of ...
    ‎Moqups · Stardock

    ReplyDelete
  23. Marketing Optimization is the process of improving the marketing efforts of an organization in an effort to maximize the desired business outcomes.


    https://crackmark.com/mediamonkey-gold-crack/

    ReplyDelete
  24. Try to minimize the scope of local variables. It's not necessary to declare them at the beginning of the method, declare them where they are first used.

    activator

    ReplyDelete

  25. You write in such an amazing style and I really enjoy visiting your website. I hope you'll continue to write like this in the future.

    SAM Broadcaster Pro 2021.4 Crack

    ReplyDelete


  26. I hope this post is beneficial for viewers. Many thanks for the shared this informative and interesting post with us.
    coolutils-pdf-splitter-pro

    ReplyDelete
  27. site!One of the most popular ways robots help doctors is by performing surgery or making operations easier. These machines make it easier to see into a patient's body and repair problems faster than human hands. So far, patients have been receptive to robots in the operating room and appreciate their precision and accuracy.

    ReplyDelete
  28. this site!
    An Aritificial Encrocrine System(AES) can make a robot fall in love with a human. Why do people fall in love? ... When this type of robot interacts with people, level of oxytocin rises in the robot in an artificial way. As exposure to a human increases,the level of oxytocin released in the robot gradually increases.27-Oct-2019

    ReplyDelete
  29. Normally I do not read post on blogs, but I wish to say that this write-up very forced me to try and do it! Your writing style has been surprised me.
    Thanks, very nice article.
    Reloader Activator

    ReplyDelete
  30. This is such a great resource that you are providing and you give it away for free what is use java program pls vist my site. Thanks.
    ableton live suite

    ReplyDelete
  31. Computer hardware is the physical parts or components of a computer, such as the monitor, mouse, keyboard,computer data storage, hard disk drive (HDD), graphic cards, sound cards, memory, motherboard, and so on, all of which are physical objects that are tangible.

    Luminar Patch!

    ReplyDelete

  32. Call Recorder crack for skype!Without software, most computers would be useless. ... Without an operating system, the browser could not run on your computer. This is in contrast to physical hardware, from which the system is built and actually performs the work. Software is easier and cheaper to change than hardware.

    ReplyDelete
  33. What a Flexible website.this websites give me lots of knowledge and information.Real Racing 3 APK + MOD

    ReplyDelete

  34. what a amazing websites please visit my websites.SnapTube MOD APK

    ReplyDelete
  35. Format HTML Styled Email using Java
    This article is for creating simple HTML Styled Email using Java. Its difficult to manage HTML code in java.

    ReplyDelete
  36. ETH is a cryptocurrency. It is scarce digital money that you can use on the internet – similar to Bitcoin. If you're new to crypto, here's how ETH is different from traditional money.


    PDF Factory pro crack!

    ReplyDelete
  37. https:/licensecracked.com/pdffactory-pro-7-35-crack-key-free-download/"The Ripple blockchain isn't open like those of other cryptocurrencies. XRP can be safely stored and kept, and uses cryptography to protect participants, but the nodes it's protecting aren't individuals but “trusted” operators registered in the Ripple network.

    ReplyDelete
  38. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to crackkeywin.com and keygeninja.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named seriallink.org

    Typing Master Pro Crack

    ReplyDelete
  39. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to crackkeywin.com and keygeninja.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named seriallink.org

    uTorrent Pro Crack

    ReplyDelete
  40. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to fcdownload.com and hussainpc.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named 4keygen.com


    Oxygen XML Editor Crack

    ReplyDelete
  41. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to fcdownload.com and hussainpc.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named profullpc.org

    SysGauge Ultimate Crack

    ReplyDelete

  42. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to fcdownload.com and hussainpc.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named 4keygen.com

    Cool Edit Pro Crack

    ReplyDelete
  43. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to fcdownload.com and hussainpc.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named profullpc.org

    Xilisoft Video Converter Ultimate Crack

    ReplyDelete
  44. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to crackkeywin.com and keygeninja.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named activatorkey.net
    Softany WinCHM Pro Crack

    ReplyDelete
  45. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to crackkeywin.com and keygeninja.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named seriallink.org

    4K Stogram Crack

    ReplyDelete
  46. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to keygeninja.com software or any other basic crack version. I always really on others to solve my basic issues. But thank fully, I recently visited a website named seriallink.org

    Aiseesoft Video Enhancer Crack

    ReplyDelete
  47. You write in such an amazing style and I really enjoy visiting your website. I hope you'll continue to write like this in the future.
    WTFast

    ReplyDelete
  48. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to crackkeywin.com and keygeninja.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named seriallink.org

    Adobe Illustrator CC Crack

    ReplyDelete
  49. I guess I am the only one who came here to share my very own experience. Guess what!? I am using my laptop for almost the past 2 years, but I had no idea of solving some basic issues. I do not know how to crackkeywin.com and keygeninja.com software or any other basic crack version. I always really on others to solve my basic issues. But thankfully, I recently visited a website named seriallink.org

    GoodSync Enterprise Crack

    ReplyDelete
  50. Nice post! This is a very nice blog that Thanks for sharing!! I will definitively come back to more times this year! Thanks for the informative post. Visit our site to know more. chimera

    ReplyDelete
  51. Your post style is super Awesome and unique from others I am visiting the page I like your style.

    Yodot RAR Repair

    ReplyDelete

  52. PDQ inventory Crack

    I like this website very much,so much fantastic information.
    In contrast to other posts on this page, yours is unique

    ReplyDelete
  53. I like your post style as it’s unique from the others I’m seeing on the page. Diskinternals Linux Reader

    ReplyDelete




  54. Many thanks for the shared this informative and interesting post with us.
    https://procracklink.com/file-viewer-plus-crack/

    ReplyDelete

  55. Many thanks for sharing such incredible knowledge. It's really good for your website.
    The info on your website inspires me greatly. This website I'm bookmarked. Maintain it and thanks again.
    I'm really impressed with your writing skills, as smart as the structure of your weblog.
    WTFAST Crack

    ReplyDelete
  56. Very fantastic.This website much more impress me.Hair Challenge APK + MOD

    ReplyDelete
  57. Hi dear,It is really enjoyable to visit your website because you have such an amazing writing style.
    Samsung Magician Crack

    ReplyDelete
  58. It is an amzaing tool. thanks for giving excilent content. You can also visit my site for more Free PC tools. Visit here.

    ReplyDelete
  59. Incredible post.It is really a useful piece of information. I’m glad that you shared this useful info with us.
    Thanks for sharing. = " https://cracked1.com/neural-dsp-fortin-nameless-suite-crack/"> neural dsp fortin nameless suite

    ReplyDelete
  60. Incredible post.It is really a useful piece of information. I’m glad that you shared this useful info with us.
    Thanks for sharing.= " https://cracked1.com/active-webcam-crack/ "> Active Webcam

    ReplyDelete
  61. Addictive Drums Crack is an easy to use program. While using the application, you can easily understand your cups. It is the only tool that can be easily used in your home. If you face artists in the industry, this is the best option for you to properly adjust the sound and music.

    ReplyDelete
  62. Redshift Render Crack combines a full biassed engine that enables greater customization with a considerably enhanced render speed when compared to CPU-based render engines. As a result, it’s a must-have for everyone working in the CGI sector.

    ReplyDelete
  63. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.
    Very interesting blog.
    Tenorshare ReiBoot Pro
    MP3jam crack

    ReplyDelete
  64. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. download Adobe Acrobat Pro DC

    ReplyDelete
  65. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. download SoundPad

    ReplyDelete
  66. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. download Sonic Academy Kick

    ReplyDelete
  67. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. download Dr.Web CureIt Crack

    ReplyDelete
  68. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. download MindMaster Pro

    ReplyDelete
  69. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. download Template Toaster

    ReplyDelete
  70. I like your all post. You have done really good work. Thank you for the information you provide, it helped me a lot. I hope to have many more entries or so from you.

    mindmaster crack

    drivermax-pro Crack

    tenorshare-ultdata-ios-for-pc crack

    easyrecovery-professional crack

    ReplyDelete
  71. This is a very informative site. It is very helpful for me. I think! it is great for any one. Thanks for the Recommendation. Like all of your content. I appreciate your work. Your knowledge was quite beneficial to me, and I appreciate you sharing it. I'd want to see many more submissions from you.
    https://crackgive.com/golang-editor-install-crack/

    ReplyDelete

  72. I am very happy to read this article. Thanks for giving us Amazing info. Fantastic post.
    Thanks For Sharing such an informative article, Im taking your feed also, Thanks.restoro license key

    ReplyDelete
  73. This comment has been removed by the author.

    ReplyDelete
  74. SoundPad crackhas made headphones/headphones that look like a standard media player. Just play your phone sounds. Play sounds on speakers and microphones. This is the default value when you play sounds with a double click or hotkey.

    ReplyDelete

Blogroll

Popular Posts