A campaign can be perfectly written and still fail when messages land in spam or bounce at the first step. This guide explains how to build an Ubuntu mail server for email marketing on Ubuntu Server 24.04 LTS, using Postfix for message transfer and Dovecot for mailbox access. You will learn how the pieces fit together, which DNS records matter, how to secure authenticated sending, and how to test the result in 2026.
Self-hosting email gives you control, but it also gives you responsibility. A working SMTP service is not automatically a trustworthy marketing platform. You must protect accounts, authenticate your domain, respect consent and unsubscribe requirements, monitor reputation, and keep a rollback plan before sending to real subscribers.
What an Ubuntu mail server actually does
Think of the mail server as a small logistics center. Postfix accepts and routes messages, DNS tells other servers where to deliver them, and Dovecot lets authorized users read mail through IMAP. TLS protects connections while they travel, while SPF, DKIM, and DMARC help receiving providers decide whether a message really represents your domain.
For a typical setup, use a dedicated hostname such as mail.example.com. Your public website can remain at example.com, while the mail host handles SMTP and mailbox traffic. Separating these roles makes troubleshooting easier and reduces the chance that a website problem affects mail delivery.
Postfix and Dovecot solve different problems:
- Postfix: sends and receives mail through SMTP and manages delivery queues.
- Dovecot: provides authenticated mailbox access, usually through IMAP.
- DNS: publishes routing and sender-authentication records.
- TLS: encrypts connections between mail clients and servers.
- Logs and monitoring: show delivery failures, authentication attempts, and abuse.
This architecture works well for a small business mailbox system or a controlled transactional service. Large marketing lists may need a specialized email service because shared reputation, feedback processing, unsubscribe handling, and provider rules are difficult to manage alone.
Plan the server before installing Postfix
Start with a clean Ubuntu Server 24.04 LTS installation, a static public IP address, and administrative access through sudo. Check your hosting provider’s policy before deployment because some providers restrict outbound port 25 or require a request to remove an SMTP block.
Give the server a fully qualified hostname and confirm that it resolves correctly. Replace example.com with your own domain in the examples below.
sudo hostnamectl set-hostname mail.example.com
hostname --fqdn
sudo apt update && sudo apt upgrade -y
You should also confirm that no other mail transfer agent is active. Running two competing SMTP services usually creates confusing port conflicts and inconsistent delivery behavior. Record your provider’s reverse-DNS process now; you will need the provider to set the PTR record for the server’s public IP.
Before changing configuration, create a simple backup directory and decide how you will restore it. A backup is useful only if you know where it is stored and how to use it.
sudo install -d -m 700 /root/mail-config-backup
sudo cp -a /etc/postfix /root/mail-config-backup/
sudo cp -a /etc/dovecot /root/mail-config-backup/
Set DNS email records and reverse DNS
Correct DNS is the foundation of email deliverability. Create an A record that points mail.example.com to the server’s public IP, then create an MX record for example.com that points to mail.example.com. The MX target should be a hostname, not an IP address.
Ask your hosting provider to set the reverse-DNS or PTR record to mail.example.com. The forward lookup and reverse lookup should agree. When they do not, receiving systems may treat the server as poorly configured even when Postfix itself works.
Add sender authentication before your first campaign:
- SPF: a TXT record that lists which servers may send for your domain. Keep one SPF record for the domain rather than publishing several separate SPF records.
- DKIM: a digital signature added to outgoing messages. The public key goes in DNS, while the private key stays on the server.
- DMARC: a policy that checks whether SPF or DKIM aligns with the visible From domain and reports results.
Begin DMARC with a monitoring policy while you confirm that legitimate sources pass. A typical starting record looks like this:
Host: _dmarc.example.com
Type: TXT
Value: v=DMARC1; p=none; rua=mailto:[email protected]
Do not copy an SPF or DKIM value from a random tutorial. Your actual sending hosts, selector name, and provider instructions determine those records. Keep a written inventory of every service allowed to send mail for the domain.
Install Postfix and choose a local mailbox format
Install Postfix and choose Internet Site when the package asks how mail should be configured. Use the server’s mail hostname when prompted.
sudo apt install postfix
sudo postfix check
sudo systemctl enable --now postfix
For a straightforward local mailbox, Maildir stores each message as an individual file inside the user’s home directory. Set it in /etc/postfix/main.cf:
home_mailbox = Maildir/
Also review the identity and destination settings rather than blindly replacing the entire file. A small installation may use values similar to these:
myhostname = mail.example.com
mydomain = example.com
myorigin = $mydomain
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain
inet_interfaces = all
home_mailbox = Maildir/
Keep mydestination limited to domains that this server should accept locally. A common mistake is adding every domain the organization owns, including domains whose mail is hosted elsewhere. That can cause unexpected local delivery or rejected messages.
Configure Dovecot and authenticated SMTP
Install Dovecot’s core and IMAP packages, then point Dovecot to the same Maildir location used by Postfix.
sudo apt install dovecot-core dovecot-imapd
sudo systemctl enable --now dovecot
In /etc/dovecot/conf.d/10-mail.conf, set:
mail_location = maildir:~/Maildir
Authenticated SMTP means a mail client must prove its identity before it can submit outgoing mail. Use TCP 587 for message submission and require TLS before accepting credentials. In /etc/postfix/master.cf, enable the submission service:
submission inet n - y - - smtpd
-o syslog_name=postfix/submission
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
-o smtpd_tls_auth_only=yes
The exact SASL connection between Postfix and Dovecot depends on the authentication settings installed on your system. Confirm that Postfix can reach Dovecot’s authentication socket, then test with a dedicated low-privilege mailbox. Never enable unauthenticated relay. An open relay can be abused quickly and can damage your domain and IP reputation.
Apply TLS and basic mail server security
TLS encrypts the connection between a mail client and the server. Obtain a certificate for the mail hostname from a trusted certificate authority, protect the private key, and reference the certificate paths in Postfix.
smtpd_tls_cert_file=/etc/ssl/certs/mail.example.com-fullchain.pem
smtpd_tls_key_file=/etc/ssl/private/mail.example.com-key.pem
smtpd_tls_security_level=may
smtpd_tls_auth_only=yes
For port 587, the submission override should require encryption, as shown earlier. Port 25 is used for server-to-server delivery, where encryption support varies by the receiving server. Do not advertise a secure connection that your certificate or configuration cannot actually provide.
Use a firewall and expose only the services you need. SSH should be limited to trusted administration methods, while port 587 is needed for authenticated submission. Open port 25 only when this server must deliver mail directly to other servers. Do not open port 465 unless you intentionally configure implicit TLS for that service.
sudo ufw allow OpenSSH
sudo ufw allow 587/tcp
sudo ufw allow 25/tcp
sudo ufw enable
sudo ufw status verbose
Use long, unique passwords for mailboxes, disable unused accounts, keep Ubuntu updated, and consider fail2ban after confirming that its filters match your logs. Rate limits are useful, but they are not a substitute for strong credentials, restricted relay permissions, and monitoring.
Ubuntu mail server walkthrough: a safe first test
Here is a practical sequence for a small organization. Imagine that a company wants to send a monthly newsletter from [email protected] while keeping replies in an IMAP mailbox.
- Publish the A, MX, SPF, DKIM, and initial DMARC records, then wait for DNS changes to become visible.
- Install Postfix and Dovecot on the clean Ubuntu host.
- Create a mailbox account with a unique password and use it only for controlled testing.
- Configure the certificate and authenticated submission on port 587.
- Send one message to a test address at a different provider and inspect the full headers.
- Confirm that the message passes authentication, arrives in the intended folder, and produces no unexpected queue errors.
For example, the test client should connect to mail.example.com on port 587, select STARTTLS, authenticate with the test mailbox, and use a From address aligned with the domain. Do not begin by importing a large list. A small test reveals configuration mistakes without creating a broad reputation problem.
To inspect the service and configuration, run:
sudo postfix check
sudo postconf -n
sudo doveconf -n
sudo systemctl status postfix dovecot
sudo journalctl -u postfix -u dovecot --since "30 minutes ago"
You can also test the SMTP handshake with OpenSSL:
openssl s_client -connect mail.example.com:587 -starttls smtp
That command checks the TLS conversation, but it does not prove that a message will reach the inbox. Deliverability also depends on authentication alignment, IP and domain reputation, message content, recipient engagement, complaint rates, and the rules of receiving providers.
Improve email deliverability without creating abuse
Email deliverability is a process, not a single installation step. Send only to people who gave permission, identify the sender clearly, include a working unsubscribe method, and honor removal requests promptly. Keep marketing mail separate from password resets, invoices, and other transactional messages when practical.
Start with a small, engaged audience and increase volume gradually. Monitor bounces, complaints, authentication results, and queue growth. A sudden burst from a new IP can look unusual even when the message itself is legitimate.
Consider these safeguards:
- Use separate sender identities or subdomains for marketing and transactional mail.
- Set a conservative per-user and per-client sending rate.
- Reject invalid recipients before repeated delivery attempts create queue noise.
- Review DMARC reports and investigate unknown senders.
- Keep bounce and unsubscribe lists synchronized with your campaign tool.
- Never purchase or scrape an email list.
Public blocklists can provide clues, but blindly rejecting every listed address can block legitimate mail. Treat list results as one signal among many, and investigate the source of the traffic before changing policy.
Monitor, troubleshoot, and keep a rollback plan
Logs tell you whether a problem is DNS, authentication, TLS, credentials, queue delivery, or a remote rejection. Search recent Postfix entries when a message is delayed, and check Dovecot logs when users cannot authenticate or see new mail.
sudo journalctl -u postfix --since today
sudo journalctl -u dovecot --since today
mailq
sudo postqueue -p
For example, a growing queue may indicate a blocked port, DNS failure, remote throttling, or a bad destination. An authentication failure on port 587 points more often to credentials, SASL, TLS, or the client configuration. A remote rejection that mentions SPF, DKIM, or DMARC requires DNS and header inspection rather than another Postfix restart.
Before each major change, copy the relevant configuration and validate it before reloading:
sudo cp /etc/postfix/main.cf /root/mail-config-backup/main.cf.$(date +%F-%H%M)
sudo postfix check
sudo systemctl reload postfix
Back up Dovecot settings, certificate renewal instructions, DNS records, mailbox data, and campaign suppression lists. Test restoration on a safe system when possible. A backup of configuration alone will not restore lost mail or recipient records.
Common mistakes to avoid in 2026
The most damaging errors are usually operational rather than syntactic. Avoid these patterns:
- Opening relay access: accepting mail from unauthenticated clients for arbitrary destinations.
- Using one password everywhere: a compromised mailbox can become a sending channel.
- Publishing multiple SPF records: receivers may treat the SPF result as invalid.
- Ignoring reverse DNS: the server identity does not match its public IP.
- Sending before testing: a simple DNS or TLS error reaches the entire list.
- Ignoring consent and unsubscribes: technical delivery does not make unsolicited marketing acceptable.
- Relying on a single blocklist: reputation decisions need context and investigation.
Another common mistake is treating Dovecot as an outbound marketing engine. Dovecot normally provides mailbox access; Postfix handles SMTP submission and delivery. Keeping that boundary clear makes permissions and logs easier to understand.
FAQ about an Ubuntu mail server
Can I use an Ubuntu mail server for bulk email marketing?
You can, but you must manage consent, unsubscribe requests, authentication, bounce handling, reputation, and abuse controls yourself. For large or high-volume campaigns, a specialized provider may reduce operational risk.
Which ports should a mail server expose?
Port 25 is commonly used for server-to-server SMTP, while port 587 is used for authenticated client submission. Only expose IMAP ports and port 465 when your design requires them and you have configured them securely.
Do SPF, DKIM, and DMARC guarantee inbox placement?
No. They help receiving systems verify the sender, but inbox placement also depends on reputation, recipient behavior, content, bounces, complaints, and provider-specific filtering.
Why can users receive mail but not send it?
Receiving and submitting mail use different paths. Check port 587 access, TLS, SASL authentication, the client hostname and port, Postfix relay restrictions, and the relevant logs.
Final checklist for your 2026 deployment
An effective Ubuntu mail server is built in layers: correct DNS, a clearly named host, Postfix, Dovecot, TLS, authenticated submission, a restrictive firewall, and continuous monitoring. The technical configuration is only half the work; responsible list management and reputation protection determine whether marketing messages remain useful and welcome.
Before sending a real campaign, verify the hostname and PTR record, test SPF and DKIM alignment, review DMARC reports, confirm that unauthenticated relay is rejected, send to a small test group, and record the rollback steps. Then make one controlled change at a time. That disciplined approach gives your Ubuntu mail server a safer start and gives you clear evidence when something needs attention.

