LLLLSMTP Server on Ubuntu 24.04 LTS with Postfix
Step 1: Update Your System
Start by updating your package list and upgrading existing packages:
apt update apt upgrade -yFor more information on installing Postfix, see the Ubuntu Official Documentation.
Postfix is a popular mail transfer agent. Install it with:
apt install postfix -y
During installation, choose “Internet Site” when prompted. Set your system mail name to match your domain (e.g., example.com).
For more information on installing Postfix, see the Postfix documentation.
Step 3: Configure Postfix
Edit the Postfix Configuration File – Open the Postfix main configuration file.
Update the following parameters:
vim /etc/postfix/main.cf
myhostname = mail.example.commydomain = example.com myorigin = $mydomain inet_interfaces = all inet_protocols = ipv4 mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain relayhost =Replace example.com with your domain.Set up DNS records:
PTR Record: Optional but recommended for reverse DNS.
MX Record: Points to your mail server.
A Record: Points mail.example.com to your server’s IP address.
Configure Postfix to use TLS encryption.
Also: How to Set Up Let’s Encrypt SSL on Ubuntu 24.04 with Apache
vim /etc/postfix/main.cf
Configure Postfix to use TLS encryption:
smtpd_use_tls = yessmtpd_tls_security_level = maysmtpd_tls_protocols = !SSLv2, !SSLv3smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3smtpd_tls_CAfile = /etc/ssl/certs/ca-certificates.crtStep 4: Configure User Authentication (Optional)
Install SASL Packages
apt install libsasl2-modules sasl2-bin -y
Configure SASL – Open the SASL configuration file:
vi /etc/postfix/sasl/smtpd.conf
Add:
pwcheck_method = saslauthd mech_list = plain loginEnable and start the SASL authentication daemon:
systemctl enable saslauthd systemctl start saslauthdConfigure Postfix to use SASL:
vim /etc/postfix/main.cf
Add:
smtpd_sasl_type = dovecotsmtpd_sasl_auth_enable = yessmtpd_sasl_security_options = noanonymousRestart Postfix:
systemctl restart postfix
Step 5: Test Your SMTP Server
Send a test email from the command line:
echo "Test email body" | mail -s "Test Subject" recipient@example.com
Replace recipient@example.com with your email address.
For more information on installing Apache, see the official Apache documentation.
Step 6: Monitor and Maintain Your SMTP Server
Check mail logs for issues:
tail -f /var/log/mail.log
Regularly update and apply security patches.
Configure Postfix as a Send-Only SMTP Server on Ubuntu
# apt install mailutilsInternet Site->OKIf it does not show up automatically, run the following command to start it:dpkg-reconfigure postfix# vi /etc/postfix/main.cfmailbox_size_limit = 0recipient_delimiter = +inet_interfaces = loopback-onlymasquerade_domains = your_main_domain# systemctl restart postfix— Testing the SMTP Server# echo "This is the body of the email" | mail -s "This is the subject line" your_email_address — Forwarding System Mail# vi /etc/aliasespostmaster: rootroot: your_email_address# newaliases# echo "This is the body of the email" | mail -s "This is the subject line" root— Enabling SMTP Encryption# apt -y install certbot# certbot certonly --standalone --rsa-key-size 4096 --agree-tos --preferred-challenges http -d your_domain-------------Output---------Saving debug log to /var/log/letsencrypt/letsencrypt.logRequesting a certificate for aleksasavic.comSuccessfully received certificate.Certificate is saved at: /etc/letsencrypt/live/your_domain/fullchain.pemKey is saved at: /etc/letsencrypt/live/your_domain/privkey.pemThis certificate expires on 2022-07-04.These files will be updated when the certificate renews.Certbot has set up a scheduled task to automatically renew this certificate in the background.- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -If you like Certbot, please consider supporting our work by: * Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate * Donating to EFF: https://eff.org/donate-le- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -# vi /etc/postfix/main.cf# TLS parameterssmtpd_tls_cert_file=/etc/letsencrypt/live/your_domain/fullchain.pemsmtpd_tls_key_file=/etc/letsencrypt/live/your_domain/privkey.pemsmtpd_tls_security_level=maysmtp_tls_CApath=/etc/ssl/certssmtp_tls_security_level=maysmtp_tls_session_cache_database = btree:${data_directory}/smtp_scache# systemctl restart postfix# echo "This is the body of an encrypted email" | mail -s "This is the subject line" rootLLL