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 9016087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:54:24+00:00 2026-06-16T03:54:24+00:00

I am trying a to send a mail by reading contents from text file.

  • 0

I am trying a to send a mail by reading contents from text file.

File I am trying to read

Line 1
Line 2
Line 3

I have tested the code with JUnit and I get the mail with same formatting as in the text file.

Output mail using Junit

Line 1
Line 2
Line 3

But when deployed in Tomcat, I get a mail with the text but new lines are not getting recognized.

Output mail when using tomcat server

Line 1Line 2Line 3

Code that I am using to read the contents of the file.

private String readFile(String pathname) throws IOException {
        File file = new File(pathname);
        StringBuilder fileContents = new StringBuilder((int) file.length());
        Scanner scanner = new Scanner(file);
        String lineSeparator = System.getProperty("line.separator");

        try {
            while (scanner.hasNextLine()) {
                fileContents.append(scanner.nextLine() + lineSeparator);
            }
            return fileContents.toString();
        } finally {
            scanner.close();
        }
    }

I have put the server in debug mode and I can see that new line is getting appended in fileContents.toString()

I am not sure what I am missing. Anything related to character set? I am not sure….

  • 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-06-16T03:54:25+00:00Added an answer on June 16, 2026 at 3:54 am

    It has something to do with clue from Perception and nullix. How the mail is read and the HTML.

    In my case, I was testing by sending mail from a mail client which was sending out “text/html” type messages to my application. So when I am replying to that mail, the reply mail was also with “text/html” format. Hence the /n or what ever line feed type that I used was omitted.

    So while reading the mail I read only “text/plain” mime type. So while replying to this mail, I could get the new line printed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to send mail from my application server using the following code FILE
I have built a feedback page.I am trying to send mail from the page.The
I am trying to send mail from localhost.. and on doing this i have
I'm trying to send mail using phpMailer. It's my code: <?php require_once('phpmailer/class.phpmailer.php'); $mail =
I am trying to send mail via SMTP in Perl. I have written a
I`m trying to send e-mail via c# and use the following code: public static
I am trying to send an e-mail from a cron using CakePHP shell but
I am trying to send mail in PHP . I use same code for
I am trying to send a mail from my web2py app hosted on GoogleAppEngine.
I am trying to send mail from localhost using PHP. I am using the

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.