{"id":4877,"date":"2025-06-02T22:38:29","date_gmt":"2025-06-02T19:38:29","guid":{"rendered":"https:\/\/avenacloud.com\/blog\/?p=4877"},"modified":"2025-06-02T22:38:31","modified_gmt":"2025-06-02T19:38:31","slug":"set-up-a-mail-server-on-vps-easy-step-by-step-guide","status":"publish","type":"post","link":"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/","title":{"rendered":"Set Up a Mail Server on VPS: Easy Step-by-Step Guide"},"content":{"rendered":"<p>Setting up your own mail server might sound like a daunting task, but it doesn\u2019t have to be. If you\u2019re looking to take control of your email hosting, maintain privacy, and avoid costly third-party services, you\u2019ve come to the right place. In this comprehensive guide, we\u2019ll walk you through <strong>how to easily set up a mail server on your VPS<\/strong> using straightforward techniques and proven best practices.<\/p>\n<p>This isn\u2019t just about getting email to work; it\u2019s about building a secure, reliable, and professional mailing system that scales with your needs. Whether you\u2019re a small business owner, developer, or tech enthusiast, this guide is tailored for you.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Quick Summary<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Why_Set_Up_a_Mail_Server_on_Your_VPS\" >Why Set Up a Mail Server on Your VPS?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Requirements_and_Preparations_for_Setting_Up_Your_Mail_Server\" >Requirements and Preparations for Setting Up Your Mail Server<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#What_You_Need_Before_You_Begin\" >What You Need Before You Begin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Choosing_the_Right_VPS_Plan\" >Choosing the Right VPS Plan<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Step_1_Secure_Your_VPS_for_a_Mail_Server_Environment\" >Step 1: Secure Your VPS for a Mail Server Environment<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Update_Your_VPS_Packages\" >Update Your VPS Packages<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Set_Up_a_Strong_Firewall\" >Set Up a Strong Firewall<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Create_a_New_User_for_Mail_Administration\" >Create a New User for Mail Administration<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Step_2_Install_and_Configure_the_Mail_Server_Software\" >Step 2: Install and Configure the Mail Server Software<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Install_Postfix_and_Dovecot\" >Install Postfix and Dovecot<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Configure_Postfix_for_Sending_and_Receiving_Emails\" >Configure Postfix for Sending and Receiving Emails<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Configure_Dovecot_for_Email_Retrieval\" >Configure Dovecot for Email Retrieval<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Step_3_Secure_Your_Mail_Server_with_SMTP_Authentication_and_Encryption\" >Step 3: Secure Your Mail Server with SMTP Authentication and Encryption<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Enable_SMTP_Authentication_in_Postfix\" >Enable SMTP Authentication in Postfix<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Install_and_Configure_SSLTLS_for_Encryption\" >Install and Configure SSL\/TLS for Encryption<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Step_4_Configure_DNS_Records_for_Mail_Deliverability_and_Spam_Prevention\" >Step 4: Configure DNS Records for Mail Deliverability and Spam Prevention<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Update_Your_Domains_DNS_with_These_Records\" >Update Your Domain\u2019s DNS with These Records:<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Example_DNS_Records\" >Example DNS Records<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-19\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Step_5_Set_Up_DKIM_for_Email_Authentication\" >Step 5: Set Up DKIM for Email Authentication<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-20\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Install_OpenDKIM\" >Install OpenDKIM<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-21\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Configure_OpenDKIM\" >Configure OpenDKIM<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-22\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Create_Key_Directories_and_Generate_Keys\" >Create Key Directories and Generate Keys<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-23\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Configure_KeyTable_SigningTable_and_TrustedHosts\" >Configure KeyTable, SigningTable, and TrustedHosts<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-24\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Integrate_OpenDKIM_with_Postfix\" >Integrate OpenDKIM with Postfix<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-25\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Add_DKIM_TXT_Record_to_DNS\" >Add DKIM TXT Record to DNS<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-26\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Step_6_Test_Your_Mail_Server_Setup\" >Step 6: Test Your Mail Server Setup<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-27\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Send_a_Test_Email\" >Send a Test Email<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-28\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Check_DNS_Records_Propagation\" >Check DNS Records Propagation<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-29\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Verify_Mail_Server_on_VPS\" >Verify Mail Server on VPS<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-30\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Step_7_Optional_Enhancements_and_Maintenance\" >Step 7: Optional Enhancements and Maintenance<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-31\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Spam_Filtering_with_SpamAssassin\" >Spam Filtering with SpamAssassin<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-32\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Webmail_Access\" >Webmail Access<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-33\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Regular_Updates_and_Backups\" >Regular Updates and Backups<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-34\" href=\"https:\/\/avenacloud.com\/blog\/set-up-a-mail-server-on-vps-easy-step-by-step-guide\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Why_Set_Up_a_Mail_Server_on_Your_VPS\"><\/span>Why Set Up a Mail Server on Your VPS?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before diving into the technical steps, it\u2019s important to understand why hosting your own mail server on a VPS is worth considering.<\/p>\n<ul>\n<li><strong>Full Control:<\/strong> Manage your email accounts, storage, and security protocols without restrictions.<\/li>\n<li><strong>Cost Savings:<\/strong> Avoid monthly fees on external email services by leveraging your VPS resources.<\/li>\n<li><strong>Privacy and Security:<\/strong> Keep your communication private without sharing data with third parties.<\/li>\n<li><strong>Customization:<\/strong> Tailor spam filters, forwarding rules, and user permissions to match your needs.<\/li>\n<li><strong>Professionalism:<\/strong> Use your own domain email addresses enhancing your brand identity.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Requirements_and_Preparations_for_Setting_Up_Your_Mail_Server\"><\/span>Requirements and Preparations for Setting Up Your Mail Server<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To start, ensure you meet the baseline requirements and understand what resources you will need for a successful mail server setup.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"What_You_Need_Before_You_Begin\"><\/span>What You Need Before You Begin<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4882 aligncenter\" title=\"How to Easily Set Up a Mail Server on Your VPS. What You Need Before You Begin\" src=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4d30e5132685d054e0b7d59bf04a82ee.jpg\" alt=\"How to Easily Set Up a Mail Server on Your VPS. What You Need Before You Begin\" width=\"1024\" height=\"768\" srcset=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4d30e5132685d054e0b7d59bf04a82ee.jpg 1024w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4d30e5132685d054e0b7d59bf04a82ee-300x225.jpg 300w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/4d30e5132685d054e0b7d59bf04a82ee-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<ul>\n<li><strong>A VPS with Linux OS:<\/strong> Preferably Ubuntu or Debian, known for strong community support.<\/li>\n<li><strong>A Domain Name:<\/strong> Required for sending and receiving professional emails.<\/li>\n<li><strong>Basic Linux <a href=\"https:\/\/avenacloud.com\/blog\/how-to-install-pip-on-windows\/\">Command<\/a> Line Knowledge:<\/strong> Comfort with SSH and terminal commands.<\/li>\n<li><strong>Root or Sudo Access:<\/strong> Full administrative rights on the VPS.<\/li>\n<li><strong>Updated DNS Settings:<\/strong> Ability to modify MX, SPF, DKIM, and DMARC records in your domain hosting panel.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Choosing_the_Right_VPS_Plan\"><\/span>Choosing the Right VPS Plan<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Your VPS should have enough resources to handle your expected email volume efficiently. Here\u2019s a quick guideline:<\/p>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th>Estimated Email Volume<\/th>\n<th>Recommended RAM<\/th>\n<th>Recommended CPU<\/th>\n<th>Storage<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>Up to 100 emails\/day<\/td>\n<td>1 GB<\/td>\n<td>1 Core<\/td>\n<td>20 GB SSD<\/td>\n<\/tr>\n<tr>\n<td>Up to 1,000 emails\/day<\/td>\n<td>2-4 GB<\/td>\n<td>2 Cores<\/td>\n<td>50 GB SSD<\/td>\n<\/tr>\n<tr>\n<td>10,000+ emails\/day<\/td>\n<td>8+ GB<\/td>\n<td>4+ Cores<\/td>\n<td>100 GB+ SSD<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Pro tip: Start small and scale your VPS as your email volume and storage needs grow.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_1_Secure_Your_VPS_for_a_Mail_Server_Environment\"><\/span>Step 1: Secure Your VPS for a Mail Server Environment<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Security is non-negotiable when setting up your mail server. Early steps ensure your VPS is locked down against unauthorized access.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Update_Your_VPS_Packages\"><\/span>Update Your VPS Packages<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Run these commands to update your <a href=\"https:\/\/avenacloud.com\/blog\/how-to-install-pip-on-windows\/\">package<\/a> index and upgrade installed <a href=\"https:\/\/avenacloud.com\/blog\/how-to-install-pip-on-windows\/\">packages<\/a>:<\/p>\n<pre><code>sudo apt update\nsudo apt upgrade -y<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Set_Up_a_Strong_Firewall\"><\/span>Set Up a Strong Firewall<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Limit open ports to only what the mail server requires (SMTP, IMAP\/POP3, Webmail if any).<\/p>\n<pre><code>sudo ufw allow ssh\nsudo ufw allow 25\/tcp    # SMTP\nsudo ufw allow 143\/tcp   # IMAP\nsudo ufw allow 993\/tcp   # IMAPS (secure)\nsudo ufw allow 587\/tcp   # SMTP Submission\nsudo ufw enable<\/code><\/pre>\n<p>This setup shields your VPS while allowing necessary mail traffic.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Create_a_New_User_for_Mail_Administration\"><\/span>Create a New User for Mail Administration<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>It\u2019s best practice not to work as root. Create a dedicated admin user:<\/p>\n<pre><code>sudo adduser mailadmin\nsudo usermod -aG sudo mailadmin\n<\/code><\/pre>\n<p>Now, switch to this user before installing and configuring software.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_2_Install_and_Configure_the_Mail_Server_Software\"><\/span>Step 2: Install and Configure the Mail Server Software<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Several software options exist for mail servers, but Postfix and Dovecot are industry standards for SMTP and IMAP\/POP3 respectively.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Install_Postfix_and_Dovecot\"><\/span>Install Postfix and Dovecot<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>sudo apt install postfix dovecot-core dovecot-imapd -y<\/code><\/pre>\n<p>During Postfix installation, select \u201cInternet Site\u201d when prompted and enter your domain name.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Configure_Postfix_for_Sending_and_Receiving_Emails\"><\/span>Configure Postfix for Sending and Receiving Emails<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Edit Postfix main configuration file:<\/p>\n<pre><code>sudo nano \/etc\/postfix\/main.cf<\/code><\/pre>\n<p>Adjust the following lines (replace example.com with your domain):<\/p>\n<pre><code>myhostname = mail.example.com\nmydomain = example.com\nmyorigin = \/etc\/mailname\nmydestination = $myhostname, localhost.$mydomain, localhost, $mydomain\nrelayhost = \nmynetworks = 127.0.0.0\/8\ninet_interfaces = all\ninet_protocols = ipv4<\/code><\/pre>\n<p>Save and exit. Reload Postfix:<\/p>\n<pre><code>sudo systemctl restart postfix<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Configure_Dovecot_for_Email_Retrieval\"><\/span>Configure Dovecot for Email Retrieval<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Edit Dovecot\u2019s main configuration files to enable IMAP and set mail <a href=\"https:\/\/avenacloud.com\/blog\/how-to-install-pip-on-windows\/\">directory<\/a>:<\/p>\n<pre><code>sudo nano \/etc\/dovecot\/dovecot.conf\n# Ensure this line is present\nprotocols = imap pop3 lmtp\n<\/code><\/pre>\n<p>Set mail location:<\/p>\n<pre><code>sudo nano \/etc\/dovecot\/conf.d\/10-mail.conf\n# mail_location = maildir:~\/Maildir\nmail_location = maildir:\/home\/%u\/Maildir<\/code><\/pre>\n<p>Create Maildir folder for your mail user:<\/p>\n<pre><code>sudo mkdir -p \/home\/mailadmin\/Maildir\nsudo chown -R mailadmin:mailadmin \/home\/mailadmin\/Maildir\nsudo chmod -R 700 \/home\/mailadmin\/Maildir<\/code><\/pre>\n<p>Restart Dovecot:<\/p>\n<pre><code>sudo systemctl restart dovecot<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_3_Secure_Your_Mail_Server_with_SMTP_Authentication_and_Encryption\"><\/span>Step 3: Secure Your Mail Server with SMTP Authentication and Encryption<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>To prevent unauthorized use and protect data in transit, securing your mail server is vital.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Enable_SMTP_Authentication_in_Postfix\"><\/span>Enable SMTP Authentication in Postfix<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Edit your Postfix configuration to enable SASL authentication:<\/p>\n<pre><code>sudo nano \/etc\/postfix\/main.cf<\/code><\/pre>\n<p>Add or update:<\/p>\n<pre><code>smtpd_sasl_type = dovecot\nsmtpd_sasl_path = private\/auth\nsmtpd_sasl_auth_enable = yes\nsmtpd_tls_security_level = may\nsmtpd_tls_auth_only = yes\n<\/code><\/pre>\n<p>Reload Postfix:<\/p>\n<pre><code>sudo systemctl restart postfix<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Install_and_Configure_SSLTLS_for_Encryption\"><\/span>Install and Configure SSL\/TLS for Encryption<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Encrypt email traffic with <a href=\"https:\/\/avenacloud.com\/blog\/ssl-for-e-commerce-website\/\">SSL certificates<\/a>. The easiest way is to use Let\u2019s Encrypt.<\/p>\n<ul>\n<li>Install Certbot:<\/li>\n<\/ul>\n<pre><code>sudo apt install certbot -y<\/code><\/pre>\n<ul>\n<li>Obtain SSL certificate (replace mail.example.com):<\/li>\n<\/ul>\n<pre><code>sudo certbot certonly --standalone -d mail.example.com<\/code><\/pre>\n<p>Configure Postfix to use the SSL certificate:<\/p>\n<pre><code>sudo nano \/etc\/postfix\/main.cf<\/code><\/pre>\n<pre><code>smtpd_tls_cert_file = \/etc\/letsencrypt\/live\/mail.example.com\/fullchain.pem\nsmtpd_tls_key_file = \/etc\/letsencrypt\/live\/mail.example.com\/privkey.pem\nsmtpd_use_tls = yes<\/code><\/pre>\n<p>For Dovecot also configure SSL:<\/p>\n<pre><code>sudo nano \/etc\/dovecot\/conf.d\/10-ssl.conf\nssl = required\nssl_cert = &lt;\/etc\/letsencrypt\/live\/mail.example.com\/fullchain.pem\nssl_key = &lt;\/etc\/letsencrypt\/live\/mail.example.com\/privkey.pem<\/code><\/pre>\n<p>Restart services:<\/p>\n<pre><code>sudo systemctl restart postfix dovecot<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_4_Configure_DNS_Records_for_Mail_Deliverability_and_Spam_Prevention\"><\/span>Step 4: Configure DNS Records for Mail Deliverability and Spam Prevention<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Correct DNS settings are crucial to ensure your emails reach inboxes and are not marked as spam.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Update_Your_Domains_DNS_with_These_Records\"><\/span>Update Your Domain\u2019s DNS with These Records:<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ol>\n<li><strong>MX Record:<\/strong> Points to your mail server.<\/li>\n<li><strong>SPF Record:<\/strong> Authorizes your server&#8217;s IP to send email for your domain.<\/li>\n<li><strong>DKIM Record:<\/strong> Signs outgoing messages to verify they\u2019re from you.<\/li>\n<li><strong>DMARC Record:<\/strong> Instructs receiving servers how to handle unauthorized emails.<\/li>\n<\/ol>\n<h3><span class=\"ez-toc-section\" id=\"Example_DNS_Records\"><\/span>Example DNS Records<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\">\n<thead>\n<tr>\n<th>Type<\/th>\n<th>Name\/Host<\/th>\n<th>Value\/Data<\/th>\n<th>TTL<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>MX<\/td>\n<td>@<\/td>\n<td>10 mail.example.com<\/td>\n<td>3600<\/td>\n<\/tr>\n<tr>\n<td>TXT (SPF)<\/td>\n<td>@<\/td>\n<td>&#8220;v=spf1 mx ip4:YOUR_VPS_IP -all&#8221;<\/td>\n<td>3600<\/td>\n<\/tr>\n<tr>\n<td>TXT (DKIM)<\/td>\n<td>default._domainkey<\/td>\n<td>&#8220;v=DKIM1; k=rsa; p=YOUR_PUBLIC_DKIM_KEY&#8221;<\/td>\n<td>3600<\/td>\n<\/tr>\n<tr>\n<td>TXT (DMARC)<\/td>\n<td>_dmarc<\/td>\n<td>&#8220;v=DMARC1; p=none; rua=mailto:postmaster@example.com&#8221;<\/td>\n<td>3600<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>Note: Generating DKIM keys requires additional steps using a tool such as OpenDKIM, which we\u2019ll cover next.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_5_Set_Up_DKIM_for_Email_Authentication\"><\/span>Step 5: Set Up DKIM for Email Authentication<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>DKIM (DomainKeys Identified Mail) adds a digital signature to your emails, improving trust and inbox placement.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Install_OpenDKIM\"><\/span>Install OpenDKIM<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4880 aligncenter\" title=\"How to Easily Set Up a Mail Server on Your VPS. Install OpenDKIM\" src=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/707fb50f0eaac15c06dc3dcbb033adcf.jpg\" alt=\"How to Easily Set Up a Mail Server on Your VPS. Install OpenDKIM\" width=\"1024\" height=\"768\" srcset=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/707fb50f0eaac15c06dc3dcbb033adcf.jpg 1024w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/707fb50f0eaac15c06dc3dcbb033adcf-300x225.jpg 300w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/707fb50f0eaac15c06dc3dcbb033adcf-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<pre><code>sudo apt install opendkim opendkim-tools -y<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Configure_OpenDKIM\"><\/span>Configure OpenDKIM<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Create and edit the configuration:<\/p>\n<pre><code>sudo nano \/etc\/opendkim.conf<\/code><\/pre>\n<p>Paste or update with:<\/p>\n<pre><code>AutoRestart             Yes\nAutoRestartRate         10\/1h\nSyslog                  yes\nUMask                   002\nCanonicalization        relaxed\/simple\nMode                    sv\nSubDomains              no\nSocket                  inet:12345@localhost\nPidFile                 \/var\/run\/opendkim\/opendkim.pid\nUserID                  opendkim\nKeyTable                \/etc\/opendkim\/key.table\nSigningTable            \/etc\/opendkim\/signing.table\nTrustedHosts            \/etc\/opendkim\/trusted.hosts<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Create_Key_Directories_and_Generate_Keys\"><\/span>Create Key Directories and Generate Keys<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>sudo mkdir \/etc\/opendkim\/keys\/example.com\nsudo opendkim-genkey -b 2048 -d example.com -D \/etc\/opendkim\/keys\/example.com -s default -v\nsudo chown -R opendkim:opendkim \/etc\/opendkim\/keys\/example.com\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Configure_KeyTable_SigningTable_and_TrustedHosts\"><\/span>Configure KeyTable, SigningTable, and TrustedHosts<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>echo \"default._domainkey.example.com example.com:default:\/etc\/opendkim\/keys\/example.com\/default.private\" | sudo tee \/etc\/opendkim\/key.table\necho \"*@example.com default._domainkey.example.com\" | sudo tee \/etc\/opendkim\/signing.table\necho \"127.0.0.1\nlocalhost\n192.168.1.0\/24\" | sudo tee \/etc\/opendkim\/trusted.hosts\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Integrate_OpenDKIM_with_Postfix\"><\/span>Integrate OpenDKIM with Postfix<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<pre><code>sudo nano \/etc\/postfix\/main.cf<\/code><\/pre>\n<p>Add:<\/p>\n<pre><code>milter_default_action = accept\nmilter_protocol = 6\nsmtpd_milters = inet:localhost:12345\nnon_smtpd_milters = inet:localhost:12345<\/code><\/pre>\n<p>Restart services:<\/p>\n<pre><code>sudo systemctl restart opendkim\nsudo systemctl restart postfix<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Add_DKIM_TXT_Record_to_DNS\"><\/span>Add DKIM TXT Record to DNS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Retrieve your DKIM public key:<\/p>\n<pre><code>sudo cat \/etc\/opendkim\/keys\/example.com\/default.txt<\/code><\/pre>\n<p>Add the contents (without the selector and domain part) as a new TXT record named <code>default._domainkey<\/code> for your domain.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Step_6_Test_Your_Mail_Server_Setup\"><\/span>Step 6: Test Your Mail Server Setup<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Before relying on your mail server, thorough testing assures everything is running smoothly.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Send_a_Test_Email\"><\/span>Send a Test Email<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"size-full wp-image-4881 aligncenter\" title=\"How to Easily Set Up a Mail Server on Your VPS. Send a Test Email\" src=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/88c14622d11822593de3d39cdf9ea8a4.jpg\" alt=\"How to Easily Set Up a Mail Server on Your VPS. Send a Test Email\" width=\"1024\" height=\"768\" srcset=\"https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/88c14622d11822593de3d39cdf9ea8a4.jpg 1024w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/88c14622d11822593de3d39cdf9ea8a4-300x225.jpg 300w, https:\/\/avenacloud.com\/blog\/wp-content\/uploads\/2025\/05\/88c14622d11822593de3d39cdf9ea8a4-768x576.jpg 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<ul>\n<li>Use an email client (Outlook, Thunderbird, etc.) configured with your new mail server credentials.<\/li>\n<li>Send mail to an external account (e.g., Gmail) and check delivery and spam folder placement.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Check_DNS_Records_Propagation\"><\/span>Check DNS Records Propagation<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Use online tools like MX Toolbox or DNSChecker to verify MX, SPF, DKIM, and DMARC records are active.<\/li>\n<\/ul>\n<h3><span class=\"ez-toc-section\" id=\"Verify_Mail_Server_on_VPS\"><\/span>Verify Mail Server on VPS<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Test Postfix and Dovecot functionality directly on the server:<\/p>\n<pre><code>telnet localhost 25\ntelnet localhost 143<\/code><\/pre>\n<h2><span class=\"ez-toc-section\" id=\"Step_7_Optional_Enhancements_and_Maintenance\"><\/span>Step 7: Optional Enhancements and Maintenance<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Your mail server is live, but further optimizations improve security, efficiency, and user experience.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Spam_Filtering_with_SpamAssassin\"><\/span>Spam Filtering with SpamAssassin<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Reduce junk mail with SpamAssassin:<\/p>\n<pre><code>sudo apt install spamassassin -y\nsudo systemctl enable spamassassin\nsudo systemctl start spamassassin\n<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Webmail_Access\"><\/span>Webmail Access<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Consider installing webmail clients like Roundcube for browser-based email:<\/p>\n<pre><code>sudo apt install roundcube roundcube-core roundcube-mysql -y<\/code><\/pre>\n<h3><span class=\"ez-toc-section\" id=\"Regular_Updates_and_Backups\"><\/span>Regular Updates and Backups<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<ul>\n<li>Keep your software updated with frequent upgrades.<\/li>\n<li>Back up configuration files and mailboxes regularly.<\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Learning <strong>how to easily set up a mail server on your VPS<\/strong> opens doors to complete email control, enhanced privacy, and significant cost savings. By following this step-by-step guide, you\u2019ve not only built a functioning mail server but also secured and optimized it for reliability.<\/p>\n<p>Don&#8217;t settle for third-party services that limit your freedom\u2014take charge today. Start by securing your domain DNS properly, configure authentication, and continuously monitor your server\u2019s performance. The benefits of running your own mail server are worth every effort.<\/p>\n<p>Ready to elevate your business communication? Set up your mail server now, and experience email hosting on your own terms!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Setting up your own mail server might sound like a daunting task, but it doesn\u2019t have to be. If you\u2019re looking to take control of your email hosting, maintain privacy, and avoid costly third-party services, you\u2019ve come to the right&#8230; <\/p>\n","protected":false},"author":6,"featured_media":4879,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[1716,1717],"class_list":["post-4877","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-vps-vds","tag-set-up-a-mail-server-on-vps","tag-set-up-mail-server-step-by-step"],"permalink_manager":null,"_links":{"self":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts\/4877","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/comments?post=4877"}],"version-history":[{"count":3,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts\/4877\/revisions"}],"predecessor-version":[{"id":4975,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/posts\/4877\/revisions\/4975"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/media\/4879"}],"wp:attachment":[{"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/media?parent=4877"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/categories?post=4877"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/avenacloud.com\/blog\/wp-json\/wp\/v2\/tags?post=4877"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}