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

99 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
    Replies
    1. Great Article android based projects

      Java Training in Chennai

      Project Center in Chennai

      Java Training in Chennai

      projects for cse

      The Angular Training covers a wide range of topics including Components, Angular Directives, Angular Services, Pipes, security fundamentals, Routing, and Angular programmability. The new Angular TRaining will lay the foundation you need to specialise in Single Page Application developer. Angular Training

      Delete
  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. Are you an entrepreneur wanting to achieve success? By having your brand name professionally created, customers are sure to remember your brand name. Truly a great investment for the success of a business. Email Spider

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

    ReplyDelete
  13. 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
  14. 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
  15. 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
  16. 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
  17. 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
  18. 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
  19. 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
  20. 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
  21. 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
  22. i've learnt all the basics of web programing from hereWINRAR 6

    ReplyDelete
  23. 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
  24. 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
  25. 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

  26. 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


  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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

  33. 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
  34. WOW What a great website.This website much more impress me.Microsoft Toolkit 3.0.0 Crack

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

    ReplyDelete

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

    ReplyDelete
  37. 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
  38. 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
  39. 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
  40. Abode Photoshop Great post. I was checking constantly this blog and I’m impressed! Very useful information specifically the last part I care for such information a lot. I was looking for this certain info for a long time. Thank you and good luck. softwarecrack.net

    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 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
  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 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
  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 4keygen.com


    Oxygen XML Editor 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 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

  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 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
  46. 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.
    Yodot RAR Repair

    ReplyDelete
  47. 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
  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 activatorkey.net
    Softany WinCHM Pro Crack

    ReplyDelete

  49. I hope this post is beneficial for viewers. Many thanks for the shared this informative and interesting post with us.
    aimp

    ReplyDelete
  50. Hi Dear, I really like your post. Its writing style is so amazing. Thank you for sharing it.

    Typing Master Pro

    ReplyDelete
  51. 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
  52. 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
  53. 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
  54. 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
  55. 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
  56. I like your post very much it is very informative and interesting. Your posts always inspire me. Keep sharing such wonderful posts, it motivates a lot. grammarly

    ReplyDelete
  57. 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
  58. Your post style is super Awesome and unique from others I am visiting the page I like your style.

    Yodot RAR Repair

    ReplyDelete

  59. 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
  60. I like your post style as it’s unique from the others I’m seeing on the page. Diskinternals Linux Reader

    ReplyDelete




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

    ReplyDelete

  62. 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
  63. Your post style is super Awesome and unique from others I am visiting the page I like your style.
    Xilisoft Video Splitter

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

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

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

    ReplyDelete
  67. 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
  68. Hello, this sites gives very interesting information about off season camping, really i like this information which is so much beneficial to us, keep sharing such kind

    of information, Thanks for sharing this type of information. download Topaz Gigapixel AI

    ReplyDelete
  69. 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
  70. 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
  71. 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
  72. 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
  73. 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 ExpressVPN

    ReplyDelete
  74. 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
  75. 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
  76. 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
  77. 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
  78. 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
  79. 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 DAEMON Tools Lite

    ReplyDelete
  80. 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
  81. Just desire to say your article is as amazing.
    The clarity in your put up is just great and i can assume you’re a professional in this
    subject. Well together with your permission let me to seize your feed to stay updated with imminent
    english stories english short stories with moral value What is the factorial of 100

    ReplyDelete
  82. I must say it is very informative as well as interesting. Thanks to the author of this post/page for writing such wonderful lines. ATNSOFT Key Manager

    ReplyDelete
  83. 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
  84. 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
  85. This is the spot you can get helps for
    any software installation and usage.wondershare

    ReplyDelete
  86. Your Site is extremely great, and it's very helpful us this article is unique and intriguing, thank you for providing this wonderfulinformation.and check our blog site also Keep it up
    Little Snitch Crack
    startcrack.co
    crackpropc.com
    crackersoftwares.com

    ReplyDelete

Blogroll

Popular Posts