Skip to content

Mail Server Management

Prerequisites

  • Postfix installed
  • MX record configured in DNS
  • Firewall ports 25, 587 open

Procedure: Configure Postfix for a Domain

When to use: Setting up a mail server to handle email for a specific domain.

Steps:

  1. Open /etc/postfix/main.cf.

  2. Set key parameters:

    myhostname = mail.example.com
    mydomain = example.com
    myorigin = $mydomain
    inet_interfaces = all
    inet_protocols = all
    mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
    mynetworks = 127.0.0.0/8
    home_mailbox = Maildir/
    

  3. Restart Postfix:

    systemctl restart postfix
    

Troubleshooting:

  • "Address already in use": Check if another MTA (like Exim or Sendmail) is running.

Procedure: Send a Test Email

When to use: Verifying that Postfix can deliver mail locally or remotely.

Steps:

  1. Send a test message:

    echo "Test body" | sendmail "centos@localhost"
    

  2. Check logs for delivery status:

    tail -f /var/log/maillog
    
    Look for status=sent.

  3. Check if the email has arrived in /home/centos/Maildir.

Troubleshooting:

  • "Connection timed out": Firewall blocking port 25.
  • "Relay access denied": You are trying to send mail through a server that doesn't trust your IP.

Procedure: Configure Dovecot IMAP

When to use: Allowing users to retrieve email using an email client (Outlook, Thunderbird).

Steps:

  1. Edit /etc/dovecot/dovecot.conf:

    protocols = imap lmtp
    listen = *
    

  2. Edit /etc/dovecot/conf.d/10-mail.conf:

    mail_location = maildir:~/Maildir
    

  3. Edit /etc/dovecot/conf.d/10-auth.conf:

    disable_plaintext_auth = no
    auth_mechanisms = plain login
    

  4. Restart Dovecot:

    systemctl restart dovecot
    

Troubleshooting:

  • "Permission denied": Check permissions on user home directories and ~/Maildir.

Procedure: Set Up LMTP Between Postfix and Dovecot

When to use: Handing off local mail delivery from Postfix to Dovecot (better performance/indexing).

Steps:

  1. Configure Dovecot socket /etc/dovecot/conf.d/10-master.conf:

    service lmtp {
      unix_listener /var/spool/postfix/private/dovecot-lmtp {
        mode = 0600
        user = postfix
        group = postfix
      }
    }
    

  2. Configure Postfix to use LMTP /etc/postfix/main.cf:

    virtual_transport = lmtp:unix:private/dovecot-lmtp
    mailbox_transport = lmtp:unix:private/dovecot-lmtp
    

  3. Restart both services.

Troubleshooting:

  • "connect to private/dovecot-lmtp: No such file": Dovecot didn't create the socket or Postfix cannot access it (permissions).

Procedure: Test SMTP Submission with telnet

When to use: Verifying SMTP authentication and mail submission without using a mail client.

Steps:

  1. Prepare base64-encoded credentials (copy command output use it later):

    printf '\0<username>\0<password>' | base64
    

  2. Connect to port 587:

    # From remote machine (your personal computer)
    telnet mail.<your_vm_name>.sysadm.ee 587
    
    # OR from your VM
    telnet localhost 587
    

  3. Identify to the server:

    EHLO <your_vm_name>.sysadm.ee
    
  4. Authenticate:

    AUTH PLAIN <base64_string>
    

  5. Send an email:

    MAIL FROM:<marketing@<your_vm_name>.sysadm.ee>
    RCPT TO:<nagios@scoring.sysadm.ee>
    DATA
    Subject: Test email
    
    This is a test message.
    .
    

  6. Quit:

    QUIT
    

Troubleshooting:

  • "Login failed": Check /var/log/maillog. Verify username, password and base64 string.

Procedure: Define an SPF record

When to use: To improve email deliverability and prevent spoofing, define an SPF record for your domain.

Steps:

  1. Open you DNS Forward Zone file in /var/lib/knot/zones

  2. Add a TXT record

<your_vm_name>.sysadm.ee. IN TXT "v=spf1 mx -all"
  1. Validate the configuration:

    knotc conf-check
    knotc zone-check <zone>
    

  2. Reload knotc:

    knotc reload
    

  3. Verify:

    dig TXT <your_vm_name>.sysadm.ee
    

  4. Note: The DNS changes might take time to propagate

Procedure: Test IMAP Login with telnet

When to use: Verifying IMAP authentication and connectivity without a heavy email client.

Steps:

  1. Connect to port 143:

    telnet localhost 143
    

  2. Login:

    a login <username> <password>
    

  3. List folders:

    b list "" "*"
    

  4. Logout:

    c logout
    

Troubleshooting:

  • "Login failed": Check /var/log/maillog. Verify disable_plaintext_auth if testing without TLS.

Quick Reference

Action Command
Send Mail mail -s "Subj" user
Check Queue mailq
Flush Queue postfix flush
View Logs tail -f /var/log/maillog
Reload Postfix postfix reload
Dovecot Status systemctl status dovecot
  • Technologies: Postfix, Dovecot
  • Concepts: Email