MailMessage mailMessage = createMailMessage(messageHeaders);
mailMessage.setBody(new BodyPart(bodyPart.getContent(), bodyPart.getContentType()));
Stack<Message> responseStack = new Stack<Message>();
if (bodyPart instanceof AttachmentPart) {
fillStack(getEndpointAdapter().handleMessage(new DefaultMessage(mailMessageMapper.toXML(mailMessage), messageHeaders)
.setHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, bodyPart.getContentType())
.setHeader(CitrusMailMessageHeaders.MAIL_FILENAME, ((AttachmentPart) bodyPart).getFileName())), responseStack);
} else {
fillStack(getEndpointAdapter().handleMessage(new DefaultMessage(mailMessageMapper.toXML(mailMessage), messageHeaders)
.setHeader(CitrusMailMessageHeaders.MAIL_CONTENT_TYPE, bodyPart.getContentType())), responseStack);
}
if (bodyPart.hasAttachments()) {
for (AttachmentPart attachmentPart : bodyPart.getAttachments()) {