Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4037874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:24:11+00:00 2026-05-20T12:24:11+00:00

In my aplication i want to send a html template to the users email.

  • 0

In my aplication i want to send a html template to the users email. Everithing works correctly when i programatically create the html, but what i want to do now, is read the html text from within a file in my application and send it. I get a FileNotFoundException, and i dont know how to find that .txt file. See the code:

public void sendAccountActivationLinkToBuyer(String destinationEmail,
        String name) {

    // Destination of the email
    String to = destinationEmail;
    String from = "myEmail@gmail.com";

    try {
        Message message = new MimeMessage(mailSession);
        // From: is our service
        message.setFrom(new InternetAddress(from));
        // To: destination given
        message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse(to));
        message.setSubject("Registration succeded");
        // Instead of simple text, a .html template should be added here!
        message.setText(generateActivationLinkTemplate());

        Date timeStamp = new Date();
        message.setSentDate(timeStamp);

        Transport.send(message);

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }

}

private String generateActivationLinkTemplate() {
    String htmlText = "";

    try {
        File f = new File("");
        BufferedReader br = new BufferedReader(new InputStreamReader(f.getClass().getResourceAsStream("./web/emailActivationTemplate.txt")));
        String content = "";
        String line = null;

        while ((line = br.readLine()) != null) {
            content += line;
        }

    } catch (FileNotFoundException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return htmlText;
}

The second method is giving me problems, i cant find that .txt file. What should i do?
I created the folder web inside the WebContent folder,the web folder is now located right next to META-INF and WEB-INF(I think that is an appropiate place to hold my images, templates,css…) Inside the folder i manually pasted the emailActivationTemplate.txt Now i need to read from it. Any ideas?

This is the console output:

SEVERE: java.io.FileNotFoundException: .\web\emailActivationTemplate.txt (The system cannot find the path specified)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T12:24:12+00:00Added an answer on May 20, 2026 at 12:24 pm

    Put emailActivationTemplate.txt in WEB-INF/classes, and get it with

    BufferedReader br = new BufferedReader(new InputStreamReader(Thread.currentThread().getContextClassLoader().getResource("emailActivationTemplate.txt"));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send mail from my android application to given address. But now
In my application i want send a email to one account.in one button click
In my application I want to send notifications to users through their pidgin internet
I want to send an email from within my iPhone application, primarily because i
in my web-application I want to send mail for users according to pre selected
I want to send an email to user from my application with the content
I have a rails application what I want to send my users notifications when
My asp.net application send Invitation emails and conformation emails , i want to create
I want to send mail from my android application to given address. But new
I am making an application where I want to send an email using smtp

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.