@Test
  public void writesResultToSender() throws Exception {
    final String receiver = "*****@*****.**";
    createMailUser(receiver, "loginIdReceiver", "secretOfReceiver");

    String validSender = "*****@*****.**";
    createMailUser(validSender, "loginIdSender", "secretOfSender");
    sendMailTo(receiver).from(validSender).withSubject(anySubject()).andText("usedScenario");

    final String ardulink =
        makeURI(
            mockURI,
            newMapBuilder()
                .put("validfroms", validSender)
                .put("scenario.usedScenario", "D1=true;A2=123")
                .build());

    SmtpServer smtpd = mailMock.getSmtp();
    final String smtp =
        "smtp://"
            + smtpd.getBindTo()
            + ":"
            + smtpd.getPort()
            + "?username="******"loginIdReceiver"
            + "&password="******"secretOfReceiver"
            + "&debugMode=true";

    CamelContext context = new DefaultCamelContext();
    context.addRoutes(
        new RouteBuilder() {
          @Override
          public void configure() {
            from(localImap(receiver))
                .to(ardulink)
                .setHeader("to", simple("${in.header.from}"))
                .setHeader("from", simple("${in.header.to}"))
                .to(smtp);
          }
        });
    context.start();

    try {
      assertThat(
          ((String) fetchMail("loginIdSender", "secretOfSender").getContent()),
          is(
              "SwitchDigitalPinCommand [pin=1, value=true]=OK\r\n"
                  + "SwitchAnalogPinCommand [pin=2, value=123]=OK"));
    } finally {
      context.stop();
    }
  }
  @Test
  public void testLargeMessageBody() throws MessagingException, IOException {
    String to = "to@localhost";
    GreenMailUtil.sendMessageBody(
        to,
        "from@localhost",
        "Subject",
        createLargeByteArray(),
        "application/blubb",
        greenMail.getSmtp().getServerSetup());
    greenMail.waitForIncomingEmail(5000, 1);

    retrieveAndCheckBody(new Retriever(greenMail.getPop3()), to);
    retrieveAndCheckBody(new Retriever(greenMail.getImap()), to);
  }
 private void loadRoutesDefinition(
     InputStream resourceAsStream, CamelContext context, String commandName) throws Exception {
   SmtpServer smtpd = mailMock.getSmtp();
   ImapServer imapd = mailMock.getImap();
   Map<String, Object> values =
       MapBuilder.<String, Object>newMapBuilder()
           .put("imaphost", imapd.getBindTo())
           .put("imapport", imapd.getPort())
           .put("commandname", commandName)
           .put("command", "D1=true;A2=123")
           .put("smtphost", smtpd.getBindTo())
           .put("smtpport", smtpd.getPort())
           .build();
   String xml = replacePlaceHolders(toString(resourceAsStream), values);
   InputStream is = new ByteArrayInputStream(xml.getBytes());
   try {
     context.addRouteDefinitions(context.loadRoutesDefinition(is).getRoutes());
   } finally {
     is.close();
   }
 }