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:

public MailServer mailServer() {
    return CitrusEndpoints.mail()

Now we can receive the mail in the test case.

                .subject("ToDo report")
                .body("There are '1' todo entries!", "text/plain; charset=us-ascii"))
    .header(CitrusMailMessageHeaders.MAIL_SUBJECT, "ToDo report");

    .message(MailMessage.response(250, "OK"));            

The mail content is marshalled to an expected XML representation 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.