예제 #1
0
  // @Override
  protected void setContent(Object payload, Message msg, String contentType, MuleMessage message)
      throws Exception {

    if (message.getAttachmentNames().size() > 0) {
      // The content type must be multipart/mixed
      MimeMultipart multipart = new MimeMultipart("mixed");
      multipart.addBodyPart(getPayloadBodyPart(message.getPayload(), contentType));
      for (Iterator it = message.getAttachmentNames().iterator(); it.hasNext(); ) {
        String name = (String) it.next();
        BodyPart part = getBodyPartForAttachment(message.getAttachment(name), name);
        // Check message props for extra headers
        addBodyPartHeaders(part, name, message);
        multipart.addBodyPart(part);
      }
      // the payload must be set to the constructed MimeMultipart message
      payload = multipart;
      // the ContentType of the message to be sent, must be the multipart
      contentType = multipart.getContentType();
      // content type
    }
    // now the message will contain the multipart payload, and the multipart
    // contentType
    super.setContent(payload, msg, contentType, message);
  }