@Override public void writeTo(OutputStream os) throws IOException { try { if (writeBodyContentOnly) { Body body = bodyPart.getBody(); InputStream inputStream = body.getInputStream(); IOUtils.copy(inputStream, os); } else { bodyPart.writeTo(os); } } catch (MessagingException e) { throw new IOException(e); } } };