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:
-
Open
/etc/postfix/main.cf. -
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/ -
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:
-
Send a test message:
echo "Test body" | sendmail "centos@localhost" -
Check logs for delivery status:
Look fortail -f /var/log/maillogstatus=sent. -
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:
-
Edit
/etc/dovecot/dovecot.conf:protocols = imap lmtp listen = * -
Edit
/etc/dovecot/conf.d/10-mail.conf:mail_location = maildir:~/Maildir -
Edit
/etc/dovecot/conf.d/10-auth.conf:disable_plaintext_auth = no auth_mechanisms = plain login -
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:
-
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 } } -
Configure Postfix to use LMTP
/etc/postfix/main.cf:virtual_transport = lmtp:unix:private/dovecot-lmtp mailbox_transport = lmtp:unix:private/dovecot-lmtp -
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:
-
Prepare base64-encoded credentials (copy command output use it later):
printf '\0<username>\0<password>' | base64 -
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 -
Identify to the server:
EHLO <your_vm_name>.sysadm.ee -
Authenticate:
AUTH PLAIN <base64_string> -
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. . -
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:
-
Open you DNS Forward Zone file in
/var/lib/knot/zones -
Add a TXT record
<your_vm_name>.sysadm.ee. IN TXT "v=spf1 mx -all"
-
Validate the configuration:
knotc conf-check knotc zone-check <zone> -
Reload knotc:
knotc reload -
Verify:
dig TXT <your_vm_name>.sysadm.ee - 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:
-
Connect to port 143:
telnet localhost 143 -
Login:
a login <username> <password> -
List folders:
b list "" "*" -
Logout:
c logout
Troubleshooting:
- "Login failed": Check
/var/log/maillog. Verifydisable_plaintext_authif 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 |
Related Documentation¶
- Technologies: Postfix, Dovecot
- Concepts: Email