How to dump entire file content while sending mail?
<p>I have a application, which accepts xml files, upon uploading a invalid xml file it sends a mail with brief information about the file. I also need to include the entire file content <strong>Update (attachment)</strong>, what should be ideal way to do this.</p>

<p>This is what I tried (test code)</p>

<pre><code>InputStream input = new BufferedInputStream(new FileInputStream("C:\\Simon\\csmclientbenz.xml"))
byte[] buffer = new byte[8192]

try {
    for (int length = 0; (length = input.read(buffer)) != -1;) {
        System.out.write(buffer, 0, length)
    }
} finally {
    input.close()
}
</code></pre>

<p>but currently it only prints part of the file. The xml file can be as large as 6MB. What is it that I am missing? Thanks</p>

<p><strong>Update</strong></p>

<p>Sending mail code</p>

<pre><code>public void sendMail(mailProp,mailData)
{       
    logger.debug("sendMail method")

    Properties properties = System.getProperties()
    properties.setProperty("mail.smtp.host", mailProp.host)
    Session session = Session.getDefaultInstance(properties)

    try{

        MimeMessage message = new MimeMessage(session)
        message.setFrom(new InternetAddress(mailProp.from))
        message.addRecipient(Message.RecipientType.TO,new InternetAddress(mailProp.to))
        message.setSubject("Configuration failed to upload for simon@abc.com")
        message.setContent(createMessage(mailData), "text/html")
        Transport.send(message)
        System.out.println("Sent message successfully....")
    }catch (MessagingException mex) {
         mex.printStackTrace()
    }
}
</code></pre>
