title: Formatting email text from jsp in HTML format using spring
body: <p>i am implementing email service using spring, where users can enter the email subject and the Email body from the form and can send an email. Here i was able to send the email successfully..but I need to translate the line breaks/tabs entered by the user in the email body form and need to translate to the same in actual email that will be sent...as right now it don't translate the linebreaks and send all the text entered by the user in a single line..Need help in formatting this..</p>
  
  <p>img link is one of the usecase with linebreaks in my email....
  <a href="http://imgur.com/RMCOjyz" rel="nofollow">http://imgur.com/RMCOjyz</a></p>
  
  <p>below is my code...</p>
  
  <pre><code>    &lt;div class="email-sm-textDiv"&gt;
          &lt;textarea name="emailBodyTxtArea" id="emailBodyTxtArea"
              placeholder="Email Body"&gt;&lt;/textarea&gt;
     &lt;/div&gt;
  </code></pre>
  
  <p>ajax call:</p>
  
  <pre><code>submitHandler:function(form){
          var jsonObj = getData();        
          if(confirm("You are about to send Email Communication, Are you sure..?")){
          $.ajax({
              type: "POST",
              url:  $("#applicationUrl").val() +"/web/utilities/sendEmailMessage",
              dataType: 'json',
              cache:false,
              headers: { 
                  'Content-Type': 'application/json' 
                  },
              data:JSON.stringify(jsonObj),  
         });
      }
          return false;
      }
  function getData(){
              var object ={
                      emailSubject : $("#emailSubTxtArea").val(),
                      emailMsg : $("#emailBodyTxtArea").val()
  
              };
              return object;
  
  
          }
  </code></pre>
  
  <p>spring code:</p>
  
  <pre><code>    private boolean executeSendingEmail(String[] emailAddrs, String emailSubject, String emailMsg) throws MessagingException,MailException, Exception {
          MimeMessage message = null;
              try{
              message = mailSender.createMimeMessage();
               MimeMessageHelper helper = new MimeMessageHelper(message, true);
               helper.setFrom(emailFrom);
               helper.setTo(emailAddrs);
               helper.setSubject(emailSubject);
               helper.setText(emailMsg, true);
               mailSender.send(message);
               return true;
              }
              catch(MessagingException mesx){
                  mesx.printStackTrace();
                  return false;
              }
              catch(MailException mx){
                  mx.printStackTrace();
                  return false;
              }
              catch(Exception ex){
                  ex.printStackTrace();
                  return false;
              }
      }
  
  }
  </code></pre>
  
  <p>I was able to send email successfully..But it is not in the format entered by the user in the form..below is my o/p email..</p>
  
  <p>output:</p>
  
  <pre><code>HI Team, this is Test mail sending form Admin Application.... Sending this email for testing purpose... Ignore this mail.. regards, Admin.
  </code></pre>
  
  <p>So need help in formatting the email Msg entered by the user - which should be the same as entered by user..
  Thanks</p>