title: java mail logs html template to catalina.out
body: <p>I am using velocity to generate HTML template based content for the email which is to be sent, and <strong>Java Mail API</strong> with Spring's <a href="http://static.springsource.org/spring/docs/2.0.x/api/org/springframework/mail/javamail/MimeMessageHelper.html" rel="nofollow">MimeMessageHelper</a> to send emails. The problem i am facing is that while rendering, HTML template is thrown to <code>catalina.out</code> which is making the file grow in size and that is not desirable.</p>
  
  <p>I have a separate application log file where the logs are generated. Is there any way so that I can redirect this rendering to my application log file? Or may be I can stop this to be thrown at <code>catalina.out</code>.</p>
  
  <p>Below is the details which gets written while sending email</p>
  
  <pre><code>Loading javamail.default.providers from jar:file:/D:/workspace/EmailService/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/email-service/WEB-INF/lib/mail-1.4.jar!/META-INF/javamail.default.providers
  DEBUG: loading new provider protocol=imap, className=com.sun.mail.imap.IMAPStore, vendor=Sun Microsystems, Inc, version=null
  DEBUG: loading new provider protocol=imaps, className=com.sun.mail.imap.IMAPSSLStore, vendor=Sun Microsystems, Inc, version=null
  DEBUG: loading new provider protocol=smtp, className=com.sun.mail.smtp.SMTPTransport, vendor=Sun Microsystems, Inc, version=null
  DEBUG: loading new provider protocol=smtps, className=com.sun.mail.smtp.SMTPSSLTransport, vendor=Sun Microsystems, Inc, version=null
  DEBUG: loading new provider protocol=pop3, className=com.sun.mail.pop3.POP3Store, vendor=Sun Microsystems, Inc, version=null
  DEBUG: loading new provider protocol=pop3s, className=com.sun.mail.pop3.POP3SSLStore, vendor=Sun Microsystems, Inc, version=null
  DEBUG: getProvider() returning provider protocol=smtp; type=javax.mail.Provider$Type@2025b64d; class=com.sun.mail.smtp.SMTPTransport; vendor=Sun Microsystems, Inc
  DEBUG SMTP: useEhlo true, useAuth true
  DEBUG SMTP: trying to connect to host "smtp.nagarro.com", port 587, isSSL false
   220 fuseout2c MailAnyone extSMTP Tue, 23 Jul 2013 02:37:58 -0700
  DEBUG SMTP: connected to host "smtp.nagarro.com", port: 587
  
  EHLO Vaibhav202001
   250-fuseout2c Hello Vaibhav202001 [14.141.12.161]
   250-SIZE 52428800
   250-PIPELINING
   250-AUTH LOGIN
   250-STARTTLS
  250 HELP
  DEBUG SMTP: Found extension "SIZE", arg "52428800"
  DEBUG SMTP: Found extension "PIPELINING", arg ""
  DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
  DEBUG SMTP: Found extension "STARTTLS", arg ""
  DEBUG SMTP: Found extension "HELP", arg ""
  STARTTLS
  220 TLS go ahead
  EHLO Vaibhav202001
  250-fuseout2c Hello Vaibhav202001 [14.141.12.161]
  250-SIZE 52428800
  250-PIPELINING
  250-AUTH LOGIN
  250 HELP
  DEBUG SMTP: Found extension "SIZE", arg "52428800"
  DEBUG SMTP: Found extension "PIPELINING", arg ""
  DEBUG SMTP: Found extension "AUTH", arg "LOGIN"
  DEBUG SMTP: Found extension "HELP", arg ""
  DEBUG SMTP: Attempt to authenticate
  AUTH LOGIN
  334 VXNlcm5hbWU6
  anNhZy5zdXBwb3J0QG5hZ2Fycm8uY29t
  334 UGFzc3dvcmQ6
  SnNhZ0AxMjM0
  235 Authentication succeeded
  DEBUG SMTP: use8bit false
  MAIL FROM:&lt;jsagteam@nagarro.com&gt;
  250 OK
  RCPT TO:&lt;vaibhav.shukla@nagarro.com&gt;
  250 Accepted
  DEBUG SMTP: Verified Addresses
  DEBUG SMTP:   vaibhav.shukla@nagarro.com
  DATA
  354 Enter message, ending with "." on a line by itself
  Date: Fri, 26 Jul 2013 12:00:48 +0530 (IST)
  From: JSAG Team &lt;jsagteam@nagarro.com&gt;
  To: vaibhav.shukla@nagarro.com
  Message-ID: &lt;1817391686.01374820248531.JavaMail.vaibhav2020@Vaibhav202001&gt;
  Subject: JSAG Home page - subscribers list
  MIME-Version: 1.0
  Content-Type: multipart/mixed; 
  boundary="----=_Part_0_999692932.1374820244866"
  
  ------=_Part_0_999692932.1374820244866
  Content-Type: multipart/related; 
  boundary="----=_Part_1_1241615899.1374820244889"
  
  ------=_Part_1_1241615899.1374820244889
  Content-Type: text/html; charset=us-ascii
  Content-Transfer-Encoding: 7bit
  
  
            //My Email Template goes here
  
  ------=_Part_1_1241615899.1374820244889--
  
  ------=_Part_0_999692932.1374820244866--
  
  
  250 OK id=1V1Z2g-0002Rh-HO
  QUIT
  221 fuseout2c closing connection
  </code></pre>
  
  <p>And here is the logging configuration</p>
  
  <pre><code>log4j.appender.file=org.apache.log4j.RollingFileAppender
  log4j.appender.file.File=${catalina.home}/logs/email-service.log
  log4j.appender.file.MaxFileSize=1000KB
  log4j.appender.file.MaxBackupIndex=1
  log4j.appender.file.layout=org.apache.log4j.PatternLayout
  log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-4p %m%n
  log4j.appender.DatePattern='.'yyyy-MM-dd
  
  # Root logger option
  log4j.rootLogger=WARN, file
  log4j.logger.com.nagarro=WARN
  </code></pre>
  
  <p>Also the code to send email</p>
  
  <pre><code>JavaMailSender mailSender; // injected through Spring DI
  
  /**
   * The mail message.
   */
  SimpleMailMessage mailMessage; // Spring DI
  
  @Override
  public void sendEMail(final EmailServiceRequest request, byte[] data) {
      MimeMessage message = mailSender.createMimeMessage();
      OutputStream outStream = null;
      try {
  
          MimeMessageHelper helper = new MimeMessageHelper(message, true);
  
  
          // set attributes
          if (null != request.getRecipientEmailId()) {
              helper.setTo(request.getRecipientEmailId());
          }
          helper.setFrom(request.getSenderEmailId());
          helper.setSubject(request.getSubject());
          helper.setText(request.getContent(), true);
  
          // check for recipient list
          if (null != request.getRecipients() &amp;&amp; !request.getRecipients().isEmpty()) {
              InternetAddress[] recipients = new InternetAddress[request.getRecipients().size()];
  
              for (int index = 0; index &lt; request.getRecipients().size(); index++) {
                  recipients[index] = new InternetAddress(request.getRecipients().get(index));
              }
              helper.setTo(recipients);
          }
  
          // data handler
          if (null != data) {
              try {
  
                  File file = File.createTempFile(request.getAttachmentName(), "");
                  outStream = new FileOutputStream(file);
                  outStream.write(data);
  
                  helper.addAttachment(request.getAttachmentName(), file);
              } catch (IOException e) {
                  logger.error(e.getMessage(), e);
              } finally {
                  try {
                      outStream.flush();
                      outStream.close();
                  } catch (IOException e) {
                      logger.error(e.getMessage(), e);
                  }
              }
          }
  
          if (!StringUtil.isNullOrEmpty(request.getEmailIdCC())) {
              helper.addCc(request.getEmailIdCC());
          }
          if (!StringUtil.isNullOrEmpty(request.getEmailIdBCC())) {
              helper.addBcc(request.getEmailIdBCC());
          }
  
          mailSender.send(message);
      } catch (MessagingException e) {
          logger.error(e.getLocalizedMessage(), e);
      }
  }
  </code></pre>