1 # Rudimentary test checking that the Stalwart email server can:
2 # - receive some message through SMTP submission, then
3 # - serve this message through IMAP.
6 certs = import ./common/acme/server/snakeoil-certs.nix;
9 in import ./make-test-python.nix ({ lib, ... }: {
10 name = "stalwart-mail";
12 nodes.main = { pkgs, ... }: {
13 security.pki.certificateFiles = [ certs.ca.cert ];
15 services.stalwart-mail = {
18 server.hostname = domain;
20 certificate."snakeoil" = {
21 cert = "%{file:${certs.${domain}.cert}}%";
22 private-key = "%{file:${certs.${domain}.key}}%";
26 certificate = "snakeoil";
33 bind = [ "[::]:587" ];
38 bind = [ "[::]:143" ];
43 session.auth.mechanisms = "[plain]";
44 session.auth.directory = "'in-memory'";
45 storage.directory = "in-memory";
47 session.rcpt.directory = "'in-memory'";
48 queue.outbound.next-hop = "'local'";
50 directory."in-memory" = {
57 email = [ "alice@${domain}" ];
63 email = [ "bob@${domain}" ];
70 environment.systemPackages = [
71 (pkgs.writers.writePython3Bin "test-smtp-submission" { } ''
72 from smtplib import SMTP
74 with SMTP('localhost', 587) as smtp:
76 smtp.login('alice', 'foobar')
83 Subject: Some test message
85 This is a test message.
90 (pkgs.writers.writePython3Bin "test-imap-read" { } ''
91 from imaplib import IMAP4
93 with IMAP4('localhost') as imap:
95 status, [caps] = imap.login('bob', 'foobar')
98 status, [ref] = imap.search(None, 'ALL')
100 [msgId] = ref.split()
101 status, msg = imap.fetch(msgId, 'BODY[TEXT]')
102 assert status == 'OK'
103 assert msg[0][1].strip() == b'This is a test message.'
108 testScript = /* python */ ''
109 main.wait_for_unit("stalwart-mail.service")
110 main.wait_for_open_port(587)
111 main.wait_for_open_port(143)
113 main.succeed("test-smtp-submission")
114 main.succeed("test-imap-read")
118 maintainers = with lib.maintainers; [ happysalada pacien onny ];