Mail server_Dovecot configuration_Testing Receiving - SomethingWithHorizons/mailserver GitHub Wiki

Verify whether dovecot has been correctly configured for retrieving mail.

After configuring dovecot, the mail server should be capable of receiving e-mails. In order to verify the configuration, swaks is used to mimic an external SMTP server by sending emails. By mimicking an external SMTP server, a variety of happy flow and error flow scenarios can be explicitly tested.

:warning: WARNING: These tests assumes availability of the test data imported earlier!

Procedure

  1. Ensure swaks is installed on the system you are executed the tests from:

    # Clear the mail related log files
    apt install -y swaks
    
  2. Clear the mail related log files to prevent possible false positive test results later:

    # Clear the mail related log files
    echo " " > /var/log/mail.log
    echo " " > /var/log/mail.err
    echo " " > /var/log/mail.info
    
  3. Execute the following SMTP protocol tests (PASSED reflects correct operation):

    # Configure the ip address being used (to avoid having to retype it every time
    ip=<MAIL SERVER IP>
    
    # Test whether e-mails to a known user / known domain combination gets accepted
    swaks --to [email protected] --server $ip | grep "250 2.0.0 Ok: queued as" && echo "PASSED" || echo "FAILED"
    
    # Test whether e-mails to a known user/unknown domain combination get rejected
    swaks --to [email protected] --server $ip | grep "454 4.7.1 <[email protected]>: Relay access denied" && echo "PASSED" || echo "FAILED"
    
    # Test whether e-mails addressed to a known, specific, alias get accepted
    swaks --to [email protected] --server $ip | grep "250 2.0.0 Ok: queued as" && echo "PASSED" || echo "FAILED"
    
    # Test whether e-mails to a known, catchall alias get accepted
    swaks --to [email protected] --server $ip | grep "250 2.0.0 Ok: queued as" && echo "PASSED" || echo "FAILED"
    

    <MAIL SERVER IP> is local IP address (e.g. 192.168.1.x) of the mail server.

    :warning: WARNING: Don't use localhost (127.0.0.1), as this changes the server feedback!

  4. Check the mail.log whether the aliases correctly got processed:

    # Test whether the known, specific, alias correctly got resolved (during step 1 execution)
    grep "to=<[email protected]>, orig_to=<[email protected]>" /var/log/mail.log && echo "PASSED" || echo "FAILED"
    
    # Test whether the known catch-all alias correctly got resolved (during step 1 execution)
    grep "to=<[email protected]>, orig_to=<[email protected]>" /var/log/mail.log && echo "PASSED" || echo "FAILED"
    
  5. Execute the SMTP protocol scenario that cannot be executed having a catch all alias active:

    # Open mysql
    mysql
    
    -- Remove the catch-all alias from the MySQL database
    DELETE FROM `mailserver`.`aliases` WHERE `source` = '@example.org';
    exit;
    
    # Configure the ip address being used (to avoid having to retype it every time
    ip=<MAIL SERVER IP>
    
    # Test whether e-mails to an unknown user / known domain get rejected
    swaks --to [email protected] --server $ip | grep "550 5.1.1 <[email protected]>: Recipient address rejected: User unknown in virtual mailbox table" && echo "PASSED" || echo "FAILED"
    

    <MAIL SERVER IP> is local IP address (e.g. 192.168.1.x) of the mail server.

    :warning: WARNING: Don't use localhost (127.0.0.1), as this changes the server feedback!

    # Open mysql
    mysql
    
    -- Restore the catch-all entry:
    INSERT INTO `mailserver`.`aliases` (`domain`, `source`, `destination`) VALUES ('example.org', '@example.org', '[email protected]');
    exit;