This sample demonstrates the usage of mail server activities in Citrus tests. You can also read about this in reference guide.


The todo-list sample application sends out mail reports to users on demand. Citrus is able to trigger the report via Http REST API. In this sample we send out some Http REST calls and wait for the incoming mail in a single test.

First we need the mail server component in Citrus. Lets add this to the configuration:

<citrus-mail:server id="mailServer"

The mail server component needs a special XML namespace in the configuration root element.

<beans xmlns=""

Now we can receive the mail in the test case.

    .payload(new ClassPathResource("templates/mail.xml"))
    .header(CitrusMailMessageHeaders.MAIL_SUBJECT, "ToDo report");

    .payload(new ClassPathResource("templates/mail-response.xml"));            

The mail content is loaded from external file resource. Here is the mail content that we expect to arrive in the test.

<mail-message xmlns="">
  <subject>ToDo report</subject>
    <contentType>text/plain; charset=us-ascii</contentType>
    <content>There are '${entryCount}' todo entries!</content>

Citrus is able to convert mail messages to an internal XML representation. This way the content is more comfortable to compare in validation. The mail response looks like this.

<mail-response xmlns="">

In the sample the success code 250 is returned to the mail client marking that everything is ok. Here we also could place some other code and message in order to simulate mail server problems.


You can run the sample on your localhost in order to see Citrus in action. Read the instructions how to run the sample.