What is a SMTP ?
On this page
SMTP which stands for Simple Mail Transfer Protocol is the protocol used to send emails across the Internet. It defines how mail servers talk to each other and how emails are transferred.
Key Points to know.
- Works on TCP port 25 by default.
- Is a push protocol which means servers push mail to the next hop.
- Used only for sending, not receiving or reading mail, receiving happens via IMAP.
- Follows a simple text-based command structure:
HELO,MAIL FROM,RCPT TO, andDATA. - Used by services like Postfix which we use in this lab.
The goal of this lesson is to:
- Deploy your own DNS zone. Create A, MX, CAA, TXT records. Understand how DNS supports email delivery.
- Configure an SMTP server (Postfix). Install and configure Postfix, make it listen on all interfaces. Allow external SMTP connections and ensure proper mail routing.
- Validate DNS for email. Use
digto check MX record. Ensure MX points to the correct host. Understand TTL and propagation. - Troubleshoot email delivery. Check SMTP port with
ssornc. - The end goal is to be able to receive an email at your domain using your own DNS + Postfix server.
Step 1: Install and Basic Setup
Display what's currently configured.
apt update
apt install -y postfix dovecot-imapd dovecot-lmtpd mailutilsEdit your zone file.
nano /etc/bind/zones/db.angelo-mouawad.sasm.uclllabs.beWhat this does:
- nano = creates file and then opens it in nano editor
File contents to be added to the end of the file.
; A records
@ IN MX 10 mx.angelo-mouawad.sasm.uclllabs.be.
mx IN A 193.191.176.212
mail IN A 193.191.176.212Increment the serial by 1 before saving. Then reload bind.
systemctl reload bind9Confirm and verify.
dig @127.0.0.1 MX angelo-mouawad.sasm.uclllabs.be +short
dig @127.0.0.1 A mx.angelo-mouawad.sasm.uclllabs.be +shortWhat this does:
- dig = domain information groper, used to query
dnsservers
Output.
root@angelo:/#
dig @127.0.0.1 MX angelomouawad.sasm.uclllabs.be +short
dig @127.0.0.1 A mx.angelo-mouawad.sasm.uclllabs.be +short
10 mx.angelo-mouawad.sasm.uclllabs.be.
193.191.176.212
Step 2: Create V Mail User
Create vmail user and group.
groupadd -g 2000 vmail
useradd -u 2000 -g vmail -d /var/vmail -m -s /usr/sbin/nologin vmailPrepare the mail directories.
mkdir -p /var/vmail/user1 /var/vmail/user2 /var/vmail/check
chown -R vmail:vmail /var/vmail
chmod -R 700 /var/vmailWhat this does:
- mkdir = make directory
- chmod = changes who can read, write, or execute a file
- chown = changes owner of the file
Step 3: Postfix configuration
Run these commands one by one to configure postfix settings.
postconf -e "myhostname = mx.angelo-mouawad.sasm.uclllabs.be"
postconf -e "mydomain = angelo-mouawad.sasm.uclllabs.be"
postconf -e "myorigin = \$mydomain"
postconf -e "mydestination ="
postconf -e "mynetworks = 127.0.0.0/8 [::1]/128 10.0.0.0/8 172.16.0.0/12 1 92.168.0.0/16"
postconf -e "virtual_mailbox_domains = angelo-mouawad.sasm.uclllabs. be"
postconf -e "virtual_mailbox_base = /var/vmail"
postconf -e "virtual_mailbox_maps = hash:/etc/postfix/vmailbox"
postconf -e "virtual_uid_maps = static:2000"
postconf -e "virtual_gid_maps = static:2000"
postconf -e "virtual_minimum_uid = 2000"
postconf -e "virtual_transport = lmtp:unix:private/dovecot-lmtp"
postconf -e "smtpd_recipient_restrictions = permit_mynetworks, reject_ unauth_destination"
postconf -e "smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem"
postconf -e "smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key"
postconf -e "smtpd_tls_security_level=may"
postconf -e "smtp_tls_security_level=may"Edit this file.
nano /etc/mailnameFile contents for /etc/mailname.
angelo-mouawad.sasm.uclllabs.beEdit the virtual mailbox map file.
nano /etc/postfix/vmailboxFile contents for /etc/postfix/vmailbox.
user1@angelo-mouawad.sasm.uclllabs.be user1/
user2@angelo-mouawad.sasm.uclllabs.be user2/
check@angelo-mouawad.sasm.uclllabs.be check/Build the map.
postmap /etc/postfix/vmailbox
postmap -s /etc/postfix/vmailboxEdit this file.
nano /etc/postfix/main.cfFile contents for /etc/postfix/main.cf.
inet_interfaces = allRestart Postfix.
systemctl restart postfixValidate Postfix configuration.
postconf -n | egrep 'myhostname|virtual_mailbox_domains|virtual_mailbox_m aps|mynetworks|mydestination'Output.
root@angelo:/# postconf -n | egrep 'myhostname|virtual_mailbox_domains|virtual_mailbox_m aps|mynetworks|mydestination'
myhostname = mx.angelo-mouawad.sasm.uclllabs.be
virtual_mailbox_domains = angelo-mouawad.sasm.uclllabs.be
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
mydestination =
Step 4: Dovecot Configuration
Edit this file.
nano /etc/dovecot/dovecot.confFile contents for /etc/dovecot/dovecot.conf.
protocols = imap lmtp
mail_location = maildir:/var/vmail/%nEdit this file.
nano /etc/dovecot/usersFile contents for.
user1:{PLAIN}Test123
user2:{PLAIN}Test123
check:{PLAIN}Test123Set the correct permissions.
chown root:dovecot /etc/dovecot/users
chmod 640 /etc/dovecot/usersEdit this file and enable passwd-file authentication.
nano /etc/dovecot/conf.d/auth-passwdfile.conf.extFile contents for /etc/dovecot/conf.d/auth-passwdfile.conf.ext.
passdb {
driver = passwd-file
args = scheme=PLAIN username_format=%n /etc/dovecot/users
}
userdb {
driver = static
args = uid=vmail gid=vmail home=/var/vmail/%n
}
Edit the file.
nano /etc/dovecot/conf.d/10-auth.confFile contents for /etc/dovecot/conf.d/10-auth.conf.
disable_plaintext_auth = no
auth_mechanisms = plain login
!include auth-passwdfile.conf.extEdit the file.
nano /etc/dovecot/conf.d/10-master.confFile contents for /etc/dovecot/conf.d/10-master.conf.
service lmtp {
unix_listener /var/spool/postfix/private/dovecot-lmtp {
mode = 0600
user = postfix
group = postfix
}
}