diff --git a/spring-integration-adapters/.classpath b/spring-integration-adapters/.classpath
index 38dd41852e..26a5a6e354 100644
--- a/spring-integration-adapters/.classpath
+++ b/spring-integration-adapters/.classpath
@@ -3,8 +3,12 @@
+
+
+
+
@@ -13,8 +17,6 @@
-
-
diff --git a/spring-integration-adapters/ivy.xml b/spring-integration-adapters/ivy.xml
index e38e284111..138323cb53 100644
--- a/spring-integration-adapters/ivy.xml
+++ b/spring-integration-adapters/ivy.xml
@@ -20,7 +20,9 @@
+
+
diff --git a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/AbstractMailHeaderGenerator.java b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/AbstractMailHeaderGenerator.java
new file mode 100644
index 0000000000..e0ca92fb10
--- /dev/null
+++ b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/AbstractMailHeaderGenerator.java
@@ -0,0 +1,110 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.adapter.mail;
+
+import org.springframework.integration.message.Message;
+import org.springframework.mail.MailMessage;
+
+/**
+ * Base implementation for {@link MailHeaderGenerator MailHeaderGenerators}.
+ * This class is abstract. Subclasses must implement the corresponding template
+ * methods to retrieve the values for the mail message's subject, recipients,
+ * and from/reply-to addresses based on the integration {@link Message}.
+ *
+ * @author Marius Bogoevici
+ */
+public abstract class AbstractMailHeaderGenerator implements MailHeaderGenerator {
+
+ /**
+ * Retrieve the subject of an e-mail message from an integration message.
+ *
+ * @param message the integration {@link Message}
+ * @return the e-mail message subject
+ */
+ protected abstract String getSubject(Message> message);
+
+ /**
+ * Retrieve the recipients list from an integration message.
+ *
+ * @param message the integration {@link Message}
+ * @return recipients list (TO)
+ */
+ protected abstract String[] getTo(Message> message);
+
+ /**
+ * Retrieve the CC recipients list from an integration message.
+ *
+ * @param message the integration {@link Message}
+ * @return CC recipients list (e-mail addresses)
+ */
+ protected abstract String[] getCc(Message> message);
+
+ /**
+ * Retrieve the BCC recipients list from an integration message.
+ *
+ * @param message the integration {@link Message}
+ * @return BCC recipients list (e-mail addresses)
+ */
+ protected abstract String[] getBcc(Message> message);
+
+ /**
+ * Retrieve the From: e-mail address from an integration message.
+ *
+ * @param message the integration {@link Message}
+ * @return the From: e-mail address
+ */
+ protected abstract String getFrom(Message> message);
+
+ /**
+ * Retrieve the Reply To: e-mail address from an integration message.
+ *
+ * @param message the integration {@link Message}
+ * @return the ReplyTo: e-mail address
+ */
+ protected abstract String getReplyTo(Message> message);
+
+ /**
+ * Populate the mail message using the results of the template methods.
+ */
+ public final void populateMailMessageHeader(MailMessage mailMessage, Message> message) {
+ final String subject = getSubject(message);
+ final String[] to = getTo(message);
+ final String[] cc = getCc(message);
+ final String[] bcc = getBcc(message);
+ final String from = getFrom(message);
+ final String replyTo = getReplyTo(message);
+ if (subject != null) {
+ mailMessage.setSubject(subject);
+ }
+ if (to != null) {
+ mailMessage.setTo(to);
+ }
+ if (cc != null) {
+ mailMessage.setCc(cc);
+ }
+ if (bcc != null) {
+ mailMessage.setBcc(bcc);
+ }
+ if (from != null) {
+ mailMessage.setFrom(from);
+ }
+ if (replyTo != null) {
+ mailMessage.setReplyTo(replyTo);
+ }
+ }
+
+}
diff --git a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/ByteArrayMailMessageMapper.java b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/ByteArrayMailMessageMapper.java
new file mode 100644
index 0000000000..3ab0a524b8
--- /dev/null
+++ b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/ByteArrayMailMessageMapper.java
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.adapter.mail;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+
+import org.springframework.core.io.ByteArrayResource;
+import org.springframework.integration.message.AbstractMessageMapper;
+import org.springframework.integration.message.Message;
+import org.springframework.integration.message.MessageHandlingException;
+import org.springframework.mail.MailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMailMessage;
+import org.springframework.mail.javamail.MimeMessageHelper;
+import org.springframework.util.Assert;
+
+/**
+ * Message mapper used for mapping byte array messages to mail messages.
+ * Generates an e-mail message with the byte array as an attachment. The
+ * multipart mode and attachment name are configurable.
+ *
+ * @author Marius Bogoevici
+ */
+public class ByteArrayMailMessageMapper extends AbstractMessageMapper {
+
+ private final JavaMailSender mailSender;
+
+ private volatile int multipartMode = MimeMessageHelper.MULTIPART_MODE_MIXED;
+
+ private volatile String attachmentFilename = "content";
+
+
+ public ByteArrayMailMessageMapper(JavaMailSender mailSender) {
+ Assert.notNull(mailSender, "'mailSender' must not be null");
+ this.mailSender = mailSender;
+ }
+
+
+ public void setMultipartMode(int multipartMode) {
+ this.multipartMode = multipartMode;
+ }
+
+ public void setAttachmentFilename(String attachmentFilename) {
+ this.attachmentFilename = attachmentFilename;
+ }
+
+ public Message toMessage(MailMessage source) {
+ throw new UnsupportedOperationException("mapping from MailMessage to byte array not supported");
+ }
+
+ public MailMessage fromMessage(Message message) {
+ try {
+ MimeMessage mimeMessage = this.mailSender.createMimeMessage();
+ MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, this.multipartMode);
+ helper.addAttachment(this.attachmentFilename, new ByteArrayResource(message.getPayload()));
+ return new MimeMailMessage(helper);
+ }
+ catch (MessagingException e) {
+ throw new MessageHandlingException("failed to create MimeMessage", e);
+ }
+ }
+
+}
diff --git a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/MailHeaderGenerator.java b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/MailHeaderGenerator.java
new file mode 100644
index 0000000000..aa639c406c
--- /dev/null
+++ b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/MailHeaderGenerator.java
@@ -0,0 +1,39 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.adapter.mail;
+
+import org.springframework.integration.message.Message;
+import org.springframework.mail.MailMessage;
+
+/**
+ * Strategy interface for generating header information for an e-mail message
+ * from the content of the integration message. Minimal configuration should
+ * include the recipients list, the subject, from/reply-to, etc. However, this
+ * strategy allows the implementation of more complex business logic, when these
+ * parameters are depending on the integration message itself.
+ *
+ * @author Marius Bogoevici
+ */
+public interface MailHeaderGenerator {
+
+ /**
+ * Populate the e-mail message header based on the content of the
+ * integration message.
+ */
+ void populateMailMessageHeader(MailMessage mailMessage, Message> message);
+
+}
diff --git a/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/MailTargetAdapter.java b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/MailTargetAdapter.java
new file mode 100644
index 0000000000..764411a282
--- /dev/null
+++ b/spring-integration-adapters/src/main/java/org/springframework/integration/adapter/mail/MailTargetAdapter.java
@@ -0,0 +1,126 @@
+/*
+ * Copyright 2002-2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.springframework.integration.adapter.mail;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.integration.handler.MessageHandler;
+import org.springframework.integration.message.AbstractMessageMapper;
+import org.springframework.integration.message.Message;
+import org.springframework.integration.message.MessageMapper;
+import org.springframework.mail.MailMessage;
+import org.springframework.mail.SimpleMailMessage;
+import org.springframework.mail.javamail.JavaMailSender;
+import org.springframework.mail.javamail.MimeMailMessage;
+import org.springframework.util.Assert;
+
+/**
+ * A target adapter for sending mail.
+ *
+ * @author Marius Bogoevici
+ * @author Mark Fisher
+ */
+public class MailTargetAdapter implements MessageHandler, InitializingBean {
+
+ private volatile JavaMailSender mailSender;
+
+ private volatile MailHeaderGenerator mailHeaderGenerator;
+
+ private volatile MessageMapper textMessageMapper;
+
+ private volatile MessageMapper byteArrayMessageMapper;
+
+ private volatile MessageMapper