Email has been edited by Lars Heinemann (Mar 06, 2008).

(View changes)

Content:
Warning

This component has been deprecated in favor to servicemix-mail component.

We currently support MIME email sending via JavaMail. The following example shows the configuration of the JavaMail email sender component.

<sm:activationSpec componentName="mimeSender" service="foo:mimeSender">
  <sm:component><bean class="org.apache.servicemix.components.email.MimeMailSender">
    <property name="sender">
      <bean class="org.springframework.mail.javamail.JavaMailSenderImpl">
        <property name="host" value="localhost"/>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

We also support the simpler MailSender from Spring, such as to work with COS.

<sm:activationSpec componentName="emailSender" service="foo:emailSender">
  <sm:component><bean class="org.apache.servicemix.components.email.SimpleMailSender">
    <property name="sender" ref="cosMailSender"/>
  </bean></sm:component>
</sm:activationSpec>

Using message properties

The default configuration of the email sender uses the supplied message properties to figure out how to send the email. The following code shows this in use

InOnly exchange = client.createInOnlyExchange();
NormalizedMessage message = exchange.getInMessage();

message.setProperty("org.apache.servicemix.email.to", "scm@servicemix.org");
message.setProperty("org.apache.servicemix.email.from", "junit@servicemix.org");
message.setProperty("org.apache.servicemix.email.subject", "Hello from JUnit!");
message.setProperty("org.apache.servicemix.email.text", "Hi from test case: " + getName() + " running at: " + new Date());

client.sendSync(exchange);

Using expressions

You can also use Expressions to configure the various properties on the email. The following example uses a mixture of constant expression and XPath expressions. This means that the sender component will use XPath to extract information from the message content and use that to create the email.

<sm:activationSpec componentName="simpleMailSenderWithExpressions" service="foo:simpleMailSenderWithExpressions">
  <sm:component><bean class="org.apache.servicemix.components.email.SimpleMailSender">
    <property name="sender" ref="javaMailSender"/>

    <property name="marshaler">
      <bean class="org.apache.servicemix.components.email.SimpleMailMarshaler">
        <property name="from">
          <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
            <constructor-arg value="/person/email"/>
          </bean>
        </property>
        <property name="to">
          <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
            <constructor-arg value="/person/accountant/email"/>
          </bean>
        </property>
        <property name="subject">
          <bean class="org.apache.servicemix.expression.ConstantExpression">
            <constructor-arg value="Drink a beer"/>
          </bean>
        </property>
        <property name="text">
          <bean class="org.apache.servicemix.expression.JaxenStringXPathExpression">
            <constructor-arg value="concat('Hello there ', /person/name, ' how are you today?')"/>
          </bean>
        </property>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

This example uses property expressions; that is extracting properties from the message.

<sm:activationSpec componentName="simpleMailSenderWithPropertyExpressions" service="foo:simpleMailSenderWithPropertyExpressions">
  <sm:component><bean class="org.apache.servicemix.components.email.SimpleMailSender">
    <property name="sender" ref="javaMailSender"/>

    <property name="marshaler">
      <bean class="org.apache.servicemix.components.email.SimpleMailMarshaler">
        <property name="from">
          <bean class="org.apache.servicemix.expression.PropertyExpression">
            <constructor-arg value="from"/>
          </bean>
        </property>
        <property name="to">
          <bean class="org.apache.servicemix.expression.PropertyExpression">
            <constructor-arg value="to"/>
          </bean>
        </property>
        <property name="subject">
          <bean class="org.apache.servicemix.expression.ConstantExpression">
            <constructor-arg value="Subject came from expression"/>
          </bean>
        </property>
        <property name="text">
          <bean class="org.apache.servicemix.expression.PropertyExpression">
            <constructor-arg value="text"/>
          </bean>
        </property>
      </bean>
    </property>
  </bean></sm:component>
</sm:activationSpec>

Powered by Atlassian Confluence (Version: 2.2.9 Build:#527 Sep 07, 2006) - Bug/feature request

Unsubscribe or edit your notifications preferences