1

I have webpage html templates that I want to use in my java code for sending html email with Java Mail.

MimeMessage message = new MimeMessage(session);

message.setContent(html, "text/html");

I want to use the method message.setContent(html, "text/html"); I think html has to be a string. How do I get my webpage html templates into a String?

Monica
  • 11
  • 1
  • 3
  • See this question on reading a file into a string: http://stackoverflow.com/questions/326390/how-to-create-a-java-string-from-the-contents-of-a-file – Richard H Nov 09 '11 at 16:16
  • Your problem, as I understand it seems to be simply how to read a html file in your app, is this correct? – Qwerky Nov 09 '11 at 16:21
  • @Qwerky Yes, how to read it so that it's a String and it preserves the html features. I would like to use the webpage template into the setContent method. – Monica Nov 09 '11 at 16:24

1 Answers1

0

OK so I found a way.

File fFile = new File("C:\\TEMP\\newUser.html");
       String html_trimmed="";
   Scanner scanner = new Scanner(new FileReader(fFile));
    try {
      while ( scanner.hasNextLine() ){
        String s=scanner.nextLine();
        //System.out.println(s);
        String tmp= s.trim();
        html_trimmed= html_trimmed.concat(tmp);

      }
    }
    finally {         
      scanner.close();
    }`
Monica
  • 11
  • 1
  • 3