☎ +17089411327 ✉ support@goix.net Client Area
24/7 SupportDedicated Technical Support
Maximum ROIUse our SMTP earn Maximum ROI
100% UptimeOur Server 100% Uptime Based
Setting Up a Mail Server on Linux: A Beginner-Friendly Walkthrough

Setting Up a Mail Server on Linux: A Beginner-Friendly Walkthrough

Setting up your own mail server on Linux is one of those projects that teaches you more about how the internet works than almost anything else. It is also surrounded by folklore: some people call it impossibly hard, others claim it takes ten minutes. The truth sits in between. Installing the software is genuinely straightforward, and this walkthrough will take you from a blank Linux VPS to a server that sends and receives mail for your domain, with encryption and authentication configured. The part that takes care is the groundwork: DNS records, hostnames and reputation, which decide whether other servers accept your mail at all. We will therefore go slowly through the preparation, then install Postfix to send and receive, Dovecot to serve mailboxes to your devices, obtain a TLS certificate, create your first account, and test every stage before moving on. You need a VPS with a dedicated IP address, a domain you control, and basic confidence copying commands into a terminal. By the end you will understand not just what to type, but why each piece exists.

Before You Install Anything: The Groundwork

Three decisions made now will save hours later. First, choose a hostname for the server, conventionally a subdomain such as mail.example.com. This name will appear in your server's greeting, its certificates and its reverse DNS, and consistency between all of them is something receiving servers check. Second, confirm your provider allows outbound port 25 and lets you set reverse DNS; without port 25 your server cannot deliver directly, and without reverse DNS many receivers will distrust it. Third, decide your scope: one domain and a handful of users is the right first project. Virtual domains, webmail and advanced filtering can all come later, once the core works.

Update the operating system fully before installing anything, create your normal administrator account, and set the system hostname to the name you chose. Check that the server's clock is synchronised, because mail servers log, sign and validate certificates against time, and a drifting clock creates baffling errors. Also record the server's public IPv4 address, and its IPv6 address if it has one. You will use them repeatedly in DNS. If the server has IPv6, plan to configure it properly or disable mail over IPv6 deliberately; a half-configured IPv6 setup, where your domain advertises an address the server does not answer well on, is a common source of intermittent delivery problems for beginners.

Step 1: Set Up the DNS Records

DNS is the address book that tells the world where your mail lives. You need several records. An A record points your mail hostname to the server's IP address. An MX record on your main domain tells senders which host accepts your mail, and it should point to that same hostname, never directly to an IP address and ideally not to a name that is itself an alias. A PTR record, set at your provider rather than in your domain's DNS, points the IP address back to the hostname; this reverse lookup is a basic trust check. Finally, a TXT record for SPF lists the servers allowed to send for your domain, which at this stage is just this one server.

  • A record: mail.example.com points to your server IPv4 address (and AAAA for IPv6 if used)
  • MX record: example.com handled by mail.example.com
  • PTR record (set via your VPS provider): your IP points back to mail.example.com
  • SPF TXT record: authorises this server to send for the domain

Timing and Propagation

Make these changes first, before installing software, because DNS changes take time to propagate and later steps, especially the TLS certificate, depend on the hostname resolving correctly. While you wait, verify from your own computer that the hostname resolves to the right address. DKIM and DMARC records come after the server is sending, because DKIM keys are generated on the server itself. Resist the urge to publish a strict DMARC policy on day one; start in monitoring mode once sending works, so you can see reports before enforcing anything.

Step 2: Install and Configure Postfix for Sending and Receiving

Postfix is the mail transfer agent: it receives incoming mail, decides where it goes, and delivers outgoing mail to other servers. Install it from your distribution's repositories, choosing the internet site configuration when the installer asks. Then review its main configuration file and set the essentials: your hostname, your domain, the network interfaces it listens on, and the list of destinations it accepts mail for. The default configuration is conservative, which is good; your job is to describe your domain accurately, not to loosen restrictions. In particular, leave the relay controls at their defaults so the server only forwards mail for authenticated users and local delivery.

Restart Postfix and read its log while you send a test message from the command line to an external address you own, such as a personal mailbox at a large provider. The log shows the conversation with the receiving server and, if delivery fails, the reason in plain language. At this stage the message may land in the spam folder, because authentication records are not complete yet, but it should arrive. Also test the other direction by replying to it. Watching both directions work, before any mailboxes or encryption are added, proves the core routing is sound and gives you a known-good base to return to if a later change breaks something.

Step 3: Add Dovecot So Devices Can Read Mail

Postfix delivers mail; it does not serve it to phones and mail apps. That job belongs to Dovecot, which provides IMAP access so your devices can read, search and organise messages stored on the server. Install Dovecot's IMAP component, point it at the mailbox location Postfix delivers to, and make sure the two agree on the mailbox format and directory. Maildir format, which stores each message as a file, is the usual choice for new setups because it is robust and easy to back up. Enable the IMAP service, and plan to allow it only in its encrypted form on port 993, so passwords and mail are never sent in plain text once certificates are in place in the next step.

Create a test system user, send it a message, and confirm the message appears in its Maildir and that an IMAP login from your mail app shows it. This separation of concerns, Postfix for transport and Dovecot for access, is why the Linux mail stack is so durable: each program does one thing, can be restarted or upgraded independently, and logs its own activity clearly. When something goes wrong later, those separate logs tell you whether the problem is delivery, storage or access, which narrows troubleshooting enormously.

Step 4: Get a TLS Certificate and Turn On Encryption

Your server needs a TLS certificate for its mail hostname so that other servers and your own devices can encrypt their connections and verify they are talking to you. Automated certificate authorities make this free and quick, provided your hostname already resolves to the server, which is why DNS came first. Obtain the certificate, then configure Postfix to use it for opportunistic encryption with other servers, and Dovecot to require it for user connections. Set up automatic renewal and test the renewal process once, because certificates that expire break mail flow and user trust at the same time.

Enable Submission on Port 587

With certificates installed, also enable the submission service on port 587 in Postfix, restricted to authenticated users over TLS. This is the port your devices and applications should use to send mail. It separates user sending from server-to-server traffic on port 25, lets you apply your own sending policies, and works from networks that block port 25 for their customers, such as home broadband and hotel Wi-Fi. From this point, no password should ever cross the network unencrypted on your system, and you can close or restrict the unencrypted access ports with confidence.

Step 5: Authentication, Users and Your First Mailbox

Decide how users will be stored. For a small server, system accounts are the simplest model: each mailbox belongs to a Linux user. As you grow, virtual users stored in a file or database, separate from system logins, become easier to manage and safer, because mailbox owners get no shell access to the server. Whichever model you choose, require strong unique passwords, and configure Postfix to let Dovecot verify sender credentials for the submission service, so one authentication system serves both reading and sending. That single source of truth prevents the classic beginner bug where a user can read mail but cannot send, because the two services disagree about their password.

Create your first real mailbox, set its password, and configure a mail app on your phone or computer using the standard settings: IMAP on port 993 with SSL, SMTP submission on port 587 with STARTTLS or SSL, and the full email address as the username in most configurations. Send a message out, reply to it from outside, and confirm both directions plus the sent copy saved by your app. You now have a working personal mail server. Everything after this point is about being trusted by the rest of the internet and staying reliable over time.

Step 6: Add DKIM Signing and DMARC

Working is not the same as trusted. Two records turn your server from functional to credible. DKIM attaches a cryptographic signature to every outgoing message, proving it really came from a server holding your domain's private key. Install a DKIM signing tool such as OpenDKIM, generate a key pair for your domain, publish the public key in DNS, and configure Postfix to sign outbound mail. Send a test message to an external mailbox and inspect its authentication results to confirm the signature verifies. Keep the private key protected on the server and note the selector you used, so you can rotate keys later without breaking verification.

Roll Out DMARC in Stages

DMARC then tells receivers what to do when SPF or DKIM fail, and where to send reports about it. Publish a DMARC record in monitoring mode first, review the aggregate reports for a week or two to catch any legitimate sending source you forgot, then move to a quarantine and finally a reject policy. This staged approach is how large organisations do it, and it is entirely available to you on a small server. Together, SPF, DKIM and DMARC form the authentication trio that modern receivers, especially the big mailbox providers, expect to see aligned with your domain on every message.

Step 7: Filtering, Spam and Keeping the Server Healthy

Within days, your server will receive spam, because every mail server does. A content filter and a set of DNS blocklist checks in Postfix will remove most of it before it reaches a mailbox. Start with the basics: reject mail from known-bad sources using reputable blocklists, consider greylisting only if you accept its delivery delays, and add a scanning filter once the core is stable, allowing enough memory for it to run comfortably. Tune gradually based on what you see in the logs. Aggressive filtering on day one creates false positives you cannot yet diagnose, and a missed invoice is a worse first impression than a little spam.

Health also means routine care. Watch disk space, because mail servers fail hard when storage fills. Review the mail queue regularly; a growing queue is the earliest sign of a delivery problem. Apply security updates promptly, back up mailboxes and configuration to somewhere outside the server, and practise restoring a mailbox before you need to. If the server also hosts your website, keep the two roles in mind when planning resources: our guide to choosing between hosting types on the shared hosting page explains when a website is better on its own hosting, leaving the mail server to do one job well.

Testing Checklist Before You Rely On It

  • Hostname resolves correctly, and reverse DNS matches it
  • MX record points to the hostname and answers from outside checks
  • Mail arrives from external senders and lands in the right mailbox
  • Mail sends externally through port 587 with authentication and TLS
  • SPF, DKIM and DMARC all pass on a test message to a major provider
  • The server fails an open-relay test: it must not forward for strangers
  • Certificates renew automatically and the renewal has been tested
  • Backups run, and one mailbox has been restored from backup successfully

Work through this list with an external test account, not just local tests, because local success hides DNS and firewall problems. Several free diagnostic services will send your server test messages and analyse the headers, showing you exactly which checks pass. Keep the results. When you later change something and delivery degrades, re-running the same checks tells you what moved, and having a known-good baseline turns guesswork into comparison.

When Self-Hosting Is Not the Right Answer

Be honest about the ongoing cost: not money, but attention. A mail server needs updates, monitoring and occasional troubleshooting, and its IP reputation needs consistent behaviour over months. If that sounds like an interesting hobby or a reasonable part of your job, self-hosting is rewarding and genuinely educational. If it sounds like a burden you will neglect, your mail will suffer for it, because an unmaintained server does not stay still; it falls behind on patches and reputation until something breaks publicly.

The middle path is a managed mail platform on infrastructure you control: a server provisioned for mail, with authentication, reverse DNS and the sending stack configured by specialists, and support when queues misbehave. That is exactly what our dedicated SMTP email server plans provide, and our VPS range suits readers who want to build it themselves with full control. Either way, you now understand what is under the hood, and that understanding makes you a better judge of any mail service, including ours.

Conclusion: A Working Server, and What to Learn Next

You have prepared DNS and reverse DNS, installed Postfix for transport and Dovecot for mailbox access, encrypted everything with TLS, authenticated your users, signed mail with DKIM, published DMARC, added filtering and tested the whole system from outside. That is a real mail server, and the methodical order, groundwork first, one component at a time, testing at each stage, is the habit that separates reliable setups from fragile ones. From here, natural next steps are webmail, virtual domains for additional addresses, and more advanced filtering. If you would like the same result without the build, or a VPS provisioned and ready for you to practise on, compare our dedicated SMTP email server options and mail-ready VPS plans: start with the setup that matches the time you can genuinely give it, and enjoy the moment your first message arrives in an external inbox, sent entirely on your own infrastructure.

← Back to blog